Accès à rien tant qu'on est pas connecté⋅e

This commit is contained in:
Emmy D'Anello 2024-12-09 23:30:34 +01:00
parent ff85c8bd51
commit ead2a91410
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -1,15 +1,27 @@
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native' 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 { useColorScheme } from '@/hooks/useColorScheme'
import { StatusBar } from 'expo-status-bar' import { StatusBar } from 'expo-status-bar'
import { Provider as StoreProvider } from 'react-redux' import { Provider as StoreProvider } from 'react-redux'
import { MD3DarkTheme, MD3LightTheme, PaperProvider } from 'react-native-paper' import { MD3DarkTheme, MD3LightTheme, PaperProvider } from 'react-native-paper'
import store from '@/utils/store' import store from '@/utils/store'
import * as SecureStore from '@/utils/SecureStore'
import { useStartGeolocationServiceEffect } from '@/utils/geolocation' import { useStartGeolocationServiceEffect } from '@/utils/geolocation'
import { useEffect } from 'react'
import { useRouteInfo } from 'expo-router/build/hooks'
export default function RootLayout() { export default function RootLayout() {
useStartGeolocationServiceEffect() useStartGeolocationServiceEffect()
const colorScheme = useColorScheme() 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 ( return (
<StoreProvider store={store}> <StoreProvider store={store}>