You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating simple login/logout routes using expo router, and firebase auth.
The Story:
A "user" atom that is non-null when logged in and null when logged out.
Based on this "user" atom the root component returns either the login screen or redirects to a bottom tab navigator.
The Issue:
Once logged in, the focus moves to bottom tab navigator and if logout from there, the "user" atom becomes null,
but since root component isnt mounted, the new atom value isnt reflected there. and focus doesnt return to login screen.
After Sign Out if i manually click the link "Go to Index.js" I land on the login screen. Which means Atom is getting updated on signout, but its not triggering the rerender of the index.js
The Ask:
A solution where upon updating an atom from one screen, some other unmounted screen to be rerendered.
This might be a very basic question in react + jotai, but i couldnt find enough resources on SO etc
// Index.js ------------------------------------------import{useAtom}from"jotai";import{userAtom}from"@/atoms/user";exportdefaultfunctionIndex(){const[email,setEmail]=useState("");const[password,setPassword]=useState("");const{
signInWithEmailAndPassword,
signOut,}=useFirebaseAuth();const[user]=useAtom(userAtom);return(<Viewstyle={styles.container}>{user ? (<Redirecthref={"/home"}/>) : (<><TextInputvalue={email}onChangeText={setEmail}/><TextInputvalue={password}onChangeText={setPassword}/><Buttontitle="Sign In"onPress={()=>signInWithEmailAndPassword(email,password)}/></>)}</View>);}// useFirebaseAuth.js ------------------------------------------import{userAtom}from"@/atoms/user";importauthfrom"@react-native-firebase/auth";import{useAtom}from"jotai";import{useEffect}from"react";exportfunctionuseFirebaseAuth(){const[user,setUser]=useAtom(userAtom);constsignInWithEmailAndPassword=async(email: string,password: string)=>{try{const{ user }=awaitauth().signInWithEmailAndPassword(email,password);setUser(user);}catch(e){console.error(e);}};constsignOut=async()=>{try{awaitauth().signOut();setUser(null);}catch(e){console.error(e);}};return{
signInWithEmailAndPassword,
signOut,};}// Top.tsx -------- A screen in tab navigtor where SignOut is called ----------import{useFirebaseAuth}from"@/hooks/useFirebaseAuth";exportdefaultfunctionTop(){const{
signInWithEmailAndPassword,
signOut,}=useFirebaseAuth();return(<Viewstyle={styles.container}><Text>Home</Text><Buttontitle="Sign Out"onPress={signOut}/><Linkhref="/">Go to Index.js</Link></View>);}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am creating simple login/logout routes using expo router, and firebase auth.
The Story:
A "user" atom that is non-null when logged in and null when logged out.
Based on this "user" atom the root component returns either the login screen or redirects to a bottom tab navigator.
The Issue:
Once logged in, the focus moves to bottom tab navigator and if logout from there, the "user" atom becomes null,
but since root component isnt mounted, the new atom value isnt reflected there. and focus doesnt return to login screen.
After Sign Out if i manually click the link "Go to Index.js" I land on the login screen. Which means Atom is getting updated on signout, but its not triggering the rerender of the index.js
The Ask:
A solution where upon updating an atom from one screen, some other unmounted screen to be rerendered.
This might be a very basic question in react + jotai, but i couldnt find enough resources on SO etc
Beta Was this translation helpful? Give feedback.
All reactions