my app/index.js
is just a loader
app/_layout.tsx
const MainLayout = () => {
const [initializing, setInitializing] = useState(true);
const {isAuthenticated} = useAuth();
const segment = useSegments();
const router = useRouter();
useEffect(() => {
if (typeof isAuthenticated === 'undefined') return;
const inApp = segment[0] == '(auth)';
if (isAuthenticated && !inApp) {
router.replace('/(auth)/home');
}
else if (isAuthenticated == false) {
router.replace('/login');
}
setInitializing(false);
}, [isAuthenticated]);
return <Slot />
}
export default function RootLayout() {
return(
<AuthContextProvider>
<MainLayout />
</AuthContextProvider>
)}
the issue occurs only if there is a user and the app wants to navigate to home. if there is no user the login page shows with out any issue.