0

I'm developing an Expo React Native application using Google auth with a Firebase integration, I want to know how can I persist the auth session of a user even after one hour, I'm using the following code to store the accessToken in local storage and login the user without asking for sign in again, this is working fine but after one hour the accessToken is refeshed so the previous one doesn't work anymore and the user has to sign in again.

  useEffect(() => {
    const checkUserLoggedIn = async () => {
      const googleAccessToken = await AsyncStorage.getItem('googleAccessToken');
      console.log(googleAccessToken);
      if (googleAccessToken) {
        const auth = getAuth();
        const credential = GoogleAuthProvider.credential(null, googleAccessToken);
        try {
          const userCredential = await signInWithCredential(auth, credential);
          setCurrentUser(userCredential.user!);
          setIsLoggedIn(true);
        } catch (e) {
          console.log(e);
        }
      } else {
        setIsLoggedIn(false);
      }
    };

Is there a way to persist the session even after one hour? I've heard about onAuthStateChanged but honestly I'm not sure how to implemented in my project.

Thanks in advance.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    See: [Supported types of Auth state persistence](https://firebase.google.com/docs/auth/web/auth-state-persistence) – Sally loves Lightning Jul 01 '23 at 03:47
  • Thank you for your response, but I was talking about persistence even after the access token is expired after one hour, how can I re-authenticate the user automatically without asking it to do it manually – Daniel Erazo Jul 01 '23 at 14:12
  • Also, see: [How to persist user after Firebase Token expired in 1 hour?](https://stackoverflow.com/a/58586999/22152755) – Sally loves Lightning Jul 01 '23 at 23:18

0 Answers0