Correction mise à jour jeton authentification
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user