I'm building an authentication flow with react navigation 5. In reading the documentation, it seems best to do a ternary operation. I'm having trouble logging in (from Auth stack to Main Tabs) and logging out (from Main tabs to auth stack). I keep getting the message "The action NAVIGATE was not handled by any navigator - Do you have a screen named Login?" here is part of my App.js
render() {
if (this.state.isLoading) {
return <SplashScreen />;
}
return (
<NavigationContainer>
<Stack.Navigator>
{this.state.userToken == null ? (
// No token found, user isn't signed in
<>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="ForgotPassword" component={ForgotPasswordScreen} />
<Stack.Screen name="SignIn" component={SigninScreen} />
</>
) : (
// User is signed in
<Stack.Screen name="Main" component={MainTabs} />
)}
</Stack.Navigator>
</NavigationContainer>
)
}
When I logout, I'm issuing the following function to clear the storage and navigate back to my auth screens
onPress={() => AsyncStorage.clear().then(this.props.navigation.navigate('Login'))}
Help!
Create a separate class for handling Navigator. Store "userToken" in user reducer data after user logged in and clear user token from reducer on logout so It will automatically switch navigator from Main to Login.
Note: On Logout, don't need to call