const Stack = createNativeStackNavigator<RootNavigationProps>();
const RootNavigation = () => {
const {token, logout} = useAuth();
const dispatch = useDispatch<AppDispatch>();
const {width} = useWindowDimensions();
const {auth_user_info, loading} = useSelector(
(state: RootState) => state.authUserInfoSlice,
);
useEffect(() => {
dispatch(authUserInfoRequest({token})).then((result: any) => {
if (result.payload.message === 'Unauthenticated.') {
logout();
}
});
}, [dispatch, logout, token]);
if (token?.token === undefined) {
setTimeout(() => {
console.log('???? [RootNavigation.tsx:109]', token?.token);
return (
<Stack.Navigator
initialRouteName="Login"
screenOptions={{
headerShown: false,
animation: 'slide_from_right',
}}>
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="LoginOTP" component={LoginOTP} />
</Stack.Navigator>
);
}, 500);
}
const authenticated =
(token?.token &&
auth_user_info?.create_account_status === '1' &&
auth_user_info?.job_category_id === '3') ||
(token?.token &&
auth_user_info?.create_account_status === '1' &&
auth_user_info?.add_car_status === '1');
const hasTokenNotAuthenticated =
token?.token &&
auth_user_info?.add_car_status === '0' &&
auth_user_info?.create_account_status === '0';
const registeredButNotCar =
token?.token &&
auth_user_info?.add_car_status === '0' &&
auth_user_info?.create_account_status === '1';
if (hasTokenNotAuthenticated) {
return (
<Stack.Navigator
initialRouteName={'Register'}
screenOptions={{
headerShown: false,
animation: 'slide_from_right',
}}>
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="ScannerHomeDriver" component={ScannerHomeDriver} />
<Stack.Screen
name="CameraScreenDriver"
component={CameraScreenDriver}
/>
<Stack.Screen name="DataDriverLicense" component={DataDriverLicense} />
</Stack.Navigator>
);
} else if (registeredButNotCar) {
return (
<Stack.Navigator
initialRouteName={'ScannerHomeTechnical'}
screenOptions={{
headerShown: false,
animation: 'slide_from_right',
}}>
<Stack.Screen
name="ScannerHomeTechnical"
component={ScannerHomeTechnical}
/>
<Stack.Screen
name="CameraScreenTechnical"
component={CameraScreenTechnical}
/>
<Stack.Screen name="DataAuto" component={DataAuto} />
</Stack.Navigator>
);
}
return (
<Stack.Navigator
initialRouteName="Home"
screenOptions={{
headerShown: false,
animation: 'slide_from_right',
}}>
{authenticated && <Stack.Screen name="Home" component={Home} />}
</Stack.Navigator>
);
};
It is necessary to check the status of the registration at the time of entry and according to it it will flash and should Error. Couldn’t find any screens for the navigator. Have you defined any screens as its children? The action ‘NAVIGATE’ with payload {“name”:”Register”} was not handled by any navigator. these problems do not exist
New contributor
AUTO SHOW is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.