From e1c511c7c27034f94b8598b44467782af346b9c1 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 11 Mar 2024 14:36:04 +0000 Subject: mobile: Do the session routing in the homescreen --- packages/mobile/app/index.tsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'packages/mobile/app/index.tsx') diff --git a/packages/mobile/app/index.tsx b/packages/mobile/app/index.tsx index 557417d7..5ce20cda 100644 --- a/packages/mobile/app/index.tsx +++ b/packages/mobile/app/index.tsx @@ -1,11 +1,20 @@ -import { Link } from "expo-router"; +import { useRouter } from "expo-router"; +import { useEffect } from "react"; import { View } from "react-native"; +import { useSession } from "@/lib/session"; + export default function App() { - return ( - - Signin - Dashboard - - ); + const router = useRouter(); + const { isLoggedIn } = useSession(); + useEffect(() => { + if (isLoggedIn === undefined) { + // Wait until it's loaded + } else if (isLoggedIn) { + router.replace("dashboard"); + } else { + router.replace("signin"); + } + }, [isLoggedIn]); + return ; } -- cgit v1.3-1-g0d28