Open maimunahmed2 opened 2 months ago
The useProtectedRoute should redirect the user back to the auth route every time the user tries to visit protected route.
User gets redirected to the auth route only for the first time and not after that.
function useProtectedRoute(user: User) { const segments = useSegments(); const navigationState = useRootNavigationState(); const [hasNavigated, setHasNavigated] = React.useState(false); React.useEffect(() => { if (!navigationState?.key || hasNavigated) return; const inAuthGroup = segments[0] === "(auth)"; if (!user.uid && !inAuthGroup) { router.replace("/(auth)/sign-in"); setHasNavigated(true); } else if (user.uid && inAuthGroup) { router.replace("/(tabs)"); setHasNavigated(true); } }, [user.uid, segments, navigationState, hasNavigated]); }
I would like to open a pull request to address this issue.
PR is welcome
Steps to Reproduce:
Expected Behavior:
The useProtectedRoute should redirect the user back to the auth route every time the user tries to visit protected route.
Actual Behavior:
User gets redirected to the auth route only for the first time and not after that.
Code Snippet Causing The Issue:
Requested Action
I would like to open a pull request to address this issue.