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.