Stockage du jeton d'authentification dans le store local, permettant l'utilisation de hooks
This commit is contained in:
12
client/hooks/useAuth.ts
Normal file
12
client/hooks/useAuth.ts
Normal 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())
|
||||
}
|
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user