From ead2a914108eeb2297dbf378abb7c55f827a7436 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Mon, 9 Dec 2024 23:30:34 +0100 Subject: [PATCH] =?UTF-8?q?Acc=C3=A8s=20=C3=A0=20rien=20tant=20qu'on=20est?= =?UTF-8?q?=20pas=20connect=C3=A9=E2=8B=85e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/app/_layout.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/app/_layout.tsx b/client/app/_layout.tsx index 00d24d9..3b2285b 100644 --- a/client/app/_layout.tsx +++ b/client/app/_layout.tsx @@ -1,15 +1,27 @@ import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native' -import { Stack } from "expo-router" +import { Stack, useRouter } from "expo-router" import { useColorScheme } from '@/hooks/useColorScheme' import { StatusBar } from 'expo-status-bar' import { Provider as StoreProvider } from 'react-redux' import { MD3DarkTheme, MD3LightTheme, PaperProvider } from 'react-native-paper' import store from '@/utils/store' +import * as SecureStore from '@/utils/SecureStore' import { useStartGeolocationServiceEffect } from '@/utils/geolocation' +import { useEffect } from 'react' +import { useRouteInfo } from 'expo-router/build/hooks' export default function RootLayout() { useStartGeolocationServiceEffect() const colorScheme = useColorScheme() + const router = useRouter() + const route = useRouteInfo() + + // Si on est pas connecté⋅e, on reste sur la fenêtre de connexion + useEffect(() => { + const isLoggedIn = SecureStore.getItem("apiToken") !== null + if (!isLoggedIn && route.pathname !== "/login") + router.navigate("/login") + }, [route, router]) return (