emeraldsanto / react-native-encrypted-storage

React Native wrapper around EncryptedSharedPreferences and Keychain to provide a secure alternative to Async Storage.
https://www.npmjs.com/package/react-native-encrypted-storage
MIT License
572 stars 77 forks source link

A big issue with encryption storage when you are working with FCM tokens #95

Closed ahadtechcarrot closed 2 years ago

ahadtechcarrot commented 2 years ago

Hi guys,

Just wanted to let you know that I have faced a major issue while using Encrypted storage along with Firebase fcm token for push notifications. So the scenario is I am clearing my whole encrypted storage with EncryptedStorage.clear() after log out in my application so due to that it is deleting my FCM token as well after which I am not able to receive notification specific to that token.

For this the solution will be to use a for loop for all your encrypted storage keys while clearing the storage instead of using EncryptedStorage.clear() which will clear whole app data including your fcm token.

Solution code : created an object for all your keys you are using for encrypted storage and then remove them after log out like this :

    for (let key in LOCALSTORAGE_DATA_KEY_OBJECT) {
        EncryptedStorage.removeItem(LOCALSTORAGE_DATA_KEY_OBJECT[key])
    }

Hope this solution helps everyone out there.