'React native navigation problem after authentication
Here is my App.js
export default() => {
const [logged, setUser] = React.useState(false);
if(!logged) {
_retrieveUserData().then((userInfo) => {
if(userInfo) {
setUser(userInfo);
SplashScreen.hide();
}
});
}
return (
<NavigationContainer>
{
(logged && logged.user.type == 1)
?
(
<Drawer.Navigator drawerPosition='right' drawerContent={props => <EmployerSidebar setUser={ setUser } { ...props } />}>
<Drawer.Screen name="RoleOneScreen" component={RoleOneScreen} />
<Drawer.Screen initialParams={{ setUser }} name="Logout" component={Logout} />
</Drawer.Navigator>
)
:
(logged && logged.user.type == 2)
?
(
<Drawer.Navigator drawerPosition='right' drawerContent={props => <EmployeeSidebar user={logged} setUser={ setUser } { ...props } />}>
<Drawer.Screen name="RoleTwoScreen" component={RoleTwoScreen} />
<Drawer.Screen initialParams={{ setUser }} name="Logout" component={Logout} />
</Drawer.Navigator>
)
:
(
<AuthStack.Navigator initialRouteName="Home" screenOptions={{headerShown: false}}>
<AuthStack.Screen name="Registration" component={Registration} />
<AuthStack.Screen initialParams={{ setUser }} name="Home" component={Home} />
<AuthStack.Screen initialParams={{ setUser }} name="Login" component={Login} />
<AuthStack.Screen name="Forgot" component={Forgot} />
</AuthStack.Navigator>
)
}
</NavigationContainer>
);
}
I am using social login, once user authenticated this function will be called in home page
updateUser(user) {
if(_storeUserData(user)) { // Even if I don't use this if block same result
this.setState({ logged: true, userInfo: user, loading:false, email: '', password: '' });
this.props.route.params.setUser(user);
}
}
Here _storeUserData and _retrieveUserData is to store user information in AsyncStorage
The issue is after authentication user is landed in the home page for the 1st time and when I try 2nd time it works fine, 3rd time doesn't work 4th time fine...
Could anyone please help me to figure out this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
