Crypho / cordova-plugin-secure-storage

Secure storage plugin for Apache Cordova
MIT License
278 stars 269 forks source link

Can't seem to get to work with Ionic 3 #128

Closed mrv777 closed 7 years ago

mrv777 commented 7 years ago

Hello,

I have tried, but I can't seem to get this to work with Ionic 3. It will work if I do ionic cordova build --release android but not if I do ionic cordova build --prod --release android. No error, it just won't save the password information so when you close the app and go back into it, there is no information. This is what I have:

 constructor(
    public events: Events,
    public storage: Storage,
    private secureStorage: SecureStorage,
    private file: File
  ) {
      this.secureStorage.create('app_password')
      .then((storage: SecureStorageObject) => {
        storage.get('password0')
        .then(
          data => { this.SAVED_PASSWORD[0] = data; },
          error => console.log(error)
        );
        storage.get('password1')
        .then(
          data => { this.SAVED_PASSWORD[1] = data; },
          error => console.log(error)
        );
        storage.get('password2')
        .then(
          data => { this.SAVED_PASSWORD[2] = data; },
          error => console.log(error)
        );
        storage.get('password3')
        .then(
          data => { this.SAVED_PASSWORD[3] = data; },
          error => console.log(error)
        );
        storage.get('password4')
        .then(
          data => { this.SAVED_PASSWORD[4] = data; },
          error => console.log(error)
        );
      });

  }
login(password: string, savePassword: boolean, accountNum: number, loginType: string): void {
        if (savePassword){ 
          this.secureStorage.create('app_password')
          .then((storage: SecureStorageObject) => {
            storage.set(`password${accountNum}`, password)
            .then(
              data => { this.SAVED_PASSWORD[accountNum] = password; },
              error => console.log(error)
            );
          });
        }
}
getSavedPassword(accountNum: number): string {
    return this.SAVED_PASSWORD[accountNum];
  }

Any help is appreciated, and thank you :)

demetris-manikas commented 7 years ago

Hi. This does not seem to be a problem with the plugin. I 'll take a look a it and let you know.

mrv777 commented 7 years ago

Thanks for taking a look. I appreciate it.

So I'm guessing that it does look like I'm using the plug-in correctly?

demetris-manikas commented 7 years ago

Sorry but I don't have any keys to sign the app so as to test the resulting apk of my test app.

ggozad commented 7 years ago

Hey, We develop secure-storage for cordova and unfortunately cannot provide support for the ionic wrapper. A few things that seem problematic in your code (without necessarily being the cause of the problem).

  1. You should never use async processes in a constructor. If there is something like componentMount or equivalent use that instead.
  2. When dealing with multiple promises you probably need a way to know when they all resolved.
  3. It seems wrong to have to create the securestorage every time you want to use it. I am referring to login() for example.

I am gonna have to close this, please run the tests on cordova if you think there is a bug on our side and report back.