martinkasa / capacitor-secure-storage-plugin

Capacitor plugin for storing string values securly on iOS and Android.
MIT License
153 stars 55 forks source link

Get a key in ios #15

Closed elrafael closed 4 years ago

elrafael commented 4 years ago

Hi, I can't get a key using get method

async doLogin() {
    const key = 'password';
    const value = 'tomato';

    SecureStoragePlugin.set({ key, value }).then(val => {
        console.log(val);
    });
}
private async getSecure(key) {
    await SecureStoragePlugin.get({ key }).then(value => {
       // Do things with value
    }).catch(error => {
       console.log('Item with specified key does not exist.');
    });
}

Don't know why but I always get the message Item with specified key does not exist. although the method set returns me TRUE.

Can you help me? Rafael

elrafael commented 4 years ago

Hi, I can't get a key using get method

async doLogin() {
    const key = 'password';
    const value = 'tomato';

    SecureStoragePlugin.set({ key, value }).then(val => {
        console.log(val);
    });
}
private async getSecure(key) {
    await SecureStoragePlugin.get({ key }).then(value => {
       // Do things with value
    }).catch(error => {
       console.log('Item with specified key does not exist.');
    });
}

Don't know why but I always get the message Item with specified key does not exist. although the method set returns me TRUE.

Can you help me? Rafael

My bad!

I was trying to "Do things with value" using only value.

I need to use

private async getSecure(key) {
    await SecureStoragePlugin.get({ key }).then(value => {
       // Do things with value
      const myKey = value.value // Dear Lord.
    }).catch(error => {
       console.log('Item with specified key does not exist.');
    });
}

The catch was been fired by FirebaseAuth because I'm trying to login using an object not a string