-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate all AsyncStorage direct calls to our storage wrapper #1169
Conversation
bd26fc5
to
1db64a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this simplifies a lot the API and this seems to be retro-compatible 👍
Note to myself: update my "log to files" PR #1137 to use storage
API
@@ -66,8 +64,6 @@ export const asyncLogout = async (client?: CozyClient): Promise<null> => { | |||
|
|||
await sendKonnectorsLogs(client) | |||
await client.logout() | |||
await clearClient() | |||
await resetSessionToken() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like resetSessionToken
is not called anymore so we can remove the method implementation?
clearClient
seems to be used in a single place (in iconTable.ts
) but i'm wondering if this is not a potential bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed resetSessionToken
.
Why do you think clearClient
in iconTable.ts
may be a potential bug ? cc @acezard if you have insights here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I anticipate that clearing the client only without cleaning related CozyPersistedStorageKeys may produce bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so you mean we could replace this we the clearData
function. Good idea.
This method will be used to clear EVERYTHING in local storage. Will be used only in tests environment for the moment.
…ect AsyncStorage calls We add a new enum called DevicePersistedStorageKeys dedicated to values that : - are linked to the device (so only one value can be stored contrary to UserPersistedStorageKeys) - are not removed when logging out
…syncStorage calls
… AsyncStorage calls
Since Oauth and SessionCreated are now part of the StorageKeys object, they are also removed when calling clearData().
1db64a8
to
4e01eb4
Compare
**Previously** - StorageKey = key where data is persisted for a cozy life (so removed at log out) - DevicePersistedStorageKeys = key where data is persisted for the device life (so NOT removed at log out) **Now** - CozyPersistedStorageKeys = key where data is persisted for a cozy (so until log out) - DevicePersistedStorageKeys = key where data is persisted for the device life (so NOT removed at log out) StorageKey = CozyPersistedStorageKeys | DevicePersistedStorageKeys There is still a 3rd enum called UserPersistedStorageKeys but it is not used with the same storage wrapper so it can not be included in the new StorageKeys.
f17f3a4
to
dadc43f
Compare
We previously renamed StorageKeys to CozyPersistedDeviceKeys. clearData method was clearing StorageKeys. It now clears CozyPersistedDeviceKeys. Let's be explicit by also renaming clearData.
Now every react-native-async-storage calls are centralized in our storage wrapper. This is a prerequisite to potentially migrate to react-native-mmkv or another library.
Some cases I encountered
AsyncStorage.setItem
and is parsed afterAsyncStorage.getItem
=> because getData and storeData already does the stringify/parse, I removed the remaining
JSON.stringify
andJSON.parse
calls when migrating to getData and storeData. Ex. : Bundle, OauthAsyncStorage.setItem
=> getData will try to parse a not stringified string if there is already a value stored directly with
AsyncStorage.setItem
. I added a compatibilty check. Ex. : DefaultRedirectionUrlWhat did I test
Checklist
Before merging this PR, the following things must have been done if relevant: