Correction mise à jour jeton authentification

This commit is contained in:
2024-12-12 15:21:58 +01:00
parent 38117ade07
commit 246dae446f
6 changed files with 27 additions and 15 deletions

View File

@ -20,6 +20,16 @@ const initialState: AuthState = {
token: null,
}
export function isAuthValid({ loggedIn, token }: AuthState): boolean {
if (!loggedIn || token === null)
return false
const arrayToken = token.split('.')
const tokenPayload = JSON.parse(atob(arrayToken[1]))
const expTime: number = tokenPayload.exp * 1000
const now: number = Math.floor(new Date().getTime())
return expTime >= now
}
export const authSlice = createSlice({
name: 'auth',
initialState: initialState,