flatly-pw / mobile-app

MIT License
0 stars 0 forks source link

Problem with token caching in SecureStore #17

Closed zeraye closed 9 months ago

zeraye commented 9 months ago

There is a problem with userToken caching. When restoring token from SecureStore we should check, if it's still valid. Currently there is no backend endpoint to validate token. There is a way to validate token e.g. fetch /flats, but it's not an elegant solution. When backend team implemented endpoint to validate token, this issue should be resolved.

// App.tsx
React.useEffect(() => {
  (async () => {
    let userToken: string | null;

    try {
      userToken = await SecureStore.getItemAsync("userToken");
    } catch {
      // Token was not found in the secure store. User is not authenticated.
      userToken = null;
    }

    dispatch({ type: "RESTORE_TOKEN", token: userToken });
  })();
}, []);
zeraye commented 9 months ago

Issue resolved in https://github.com/flatly-pw/mobile-app/pull/18.