I have problem in firebase authentication - React Native.
using OnAuthStateChanged
the login process was successfully executed. but when page is refreshed/reloaded, in debugger it shows value user = 'null'
,
even though I'm logged in.
import {onAuthStateChanged} from 'firebase/auth';
import React, {useEffect} from 'react';
import {auth} from '../../utils/firebase';
export default function GetStarted({navigation}) {
useEffect(() => {
onAuthStateChanged(auth, user => {
console.log('user :', user);
if (user) {
navigation.replace('MainApp');
} else {
//
}
});
}, [navigation]);
when Logged In ---- Debugger: Loggin
When Reload/Refresh Page --- Debugger: Reload/Refresh Page
using React Native V0.71, Firebase V9 can anyone help me to solve this?, i really appreciate the help
react native needs to use AsyncStorage as persistence, change your 'auth' to initializeAuth
install AsyncStorage
npm install @react-native-async-storage/async-storage
import these
import AsyncStorage from "@react-native-async-storage/async-storage";
import { initializeAuth, getReactNativePersistence} from
'firebase/auth/react-native';
...
const Auth = initializeAuth(app, {
persistence: getReactNativePersistence(AsyncStorage)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With