martinkasa / capacitor-secure-storage-plugin

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

Getting a non-existing key on Android and in the browser #2

Closed martinsotirov closed 4 years ago

martinsotirov commented 5 years ago

When I try to get an non-existing or removed key on iOS the promise correctly gets rejected but on Android and in the browser it resolves with a weird looking value:

{"value":"\u009eée"}

I can implement a check in the resolve callback as a workaround but this might be something worth looking into.

nate-g commented 5 years ago

This value comes from calling atob(null), at least on the browser. I'm thinking it's probably something similar on Android. If I get time I'll create a PR, though I'm not currently setup to test on Android.

Nodonisko commented 4 years ago

For me it is also returning some strange values on iOS like

dennisameling commented 4 years ago

We use the following workaround for now where we check for atob(null):

return SecureStoragePlugin.get({ key }).then(val => {
            if (val.value && val.value !== atob(null)) {
                this.setOurValue(val.value);
            }
}).catch(error => {
            console.log('Error occured');
});

Will provide a PR at least for the web part when I have time.

Mageek627 commented 4 years ago

I lost some time because of this issue. I think it would be a good idea to specify that in the documentation of SecureStoragePlugin.get in the meantime, until it gets fixed.

martinkasa commented 4 years ago

Should be fixed in v0.4.0. To use this version you have to update your app to use Capacitor v2. I added getPlatform() method, so you can check if really native plugin is used and not just web "fallback".