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

12
client/hooks/useAuth.ts Normal file
View File

@ -0,0 +1,12 @@
import { useAppDispatch, useAppSelector } from "./useStore"
import { AuthPayload, login, logout } from "@/utils/features/location/authSlice"
export const useAuth = () => useAppSelector((state) => state.auth)
export const useAuthLogin = () => {
const dispath = useAppDispatch()
return (payload: AuthPayload) => dispath(login(payload))
}
export const useAuthLogout = () => {
const dispatch = useAppDispatch()
return () => dispatch(logout())
}

View File

@ -3,7 +3,7 @@ import { useAppDispatch, useAppSelector } from "./useStore"
import { setLocation } from "@/utils/features/location/locationSlice"
export const useLocation = () => useAppSelector((state) => state.location.location)
export const useSetLocation = () => (location: LocationObject) => {
export const useSetLocation = () => {
const dispatch = useAppDispatch()
dispatch(setLocation(location))
return (location: LocationObject) => dispatch(setLocation(location))
}