Stockage du jeton d'authentification dans le store local, permettant l'utilisation de hooks

This commit is contained in:
2024-12-10 18:56:50 +01:00
parent 72862da3a6
commit 363dfa5c74
8 changed files with 108 additions and 31 deletions

View File

@ -0,0 +1,25 @@
import { useAuth } from "@/hooks/useAuth"
import { Href, useRouter } from "expo-router"
import { useRouteInfo } from "expo-router/build/hooks"
import { ReactNode, useEffect } from "react"
type Props = {
loginRedirect: Href
children: ReactNode
}
export default function LoginProvider({ loginRedirect, children }: Props) {
const router = useRouter()
const route = useRouteInfo()
// Si on est pas connecté⋅e, on reste sur la fenêtre de connexion
const auth = useAuth()
useEffect(() => {
if (!auth.loggedIn && route.pathname !== loginRedirect)
router.navigate(loginRedirect)
}, [auth, route, router])
return <>
{children}
</>
}