I'm using this screen to navigate between two screens by using the onAuthStateChanged but still every time It refresh the app it logs out even though I'm not log out.
import { View, Text, ActivityIndicator } from 'react-native'
import React, {useEffect } from 'react'
import { auth } from '../firebase';
import { useNavigation } from '@react-navigation/native';
const LoadingScreen = () => {
const navigation = useNavigation()
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged(user =>{
if(user){
navigation.replace('Chats')
//navigate to chat screen if user is exists
}else{
navigation.replace('Welcome')
//else navigate to first screen if no user
}
})
return unsubscribe
},[])
return (
<View >
<ActivityIndicator size='large' />
</View>
);
}
export default LoadingScreen