Skip to content

Commit

Permalink
Cerbère - Ajout d'un silent renew si le token est déjà expiré (#3536)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #3535

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron committed Aug 29, 2024
2 parents 08199e4 + 4973950 commit 5ca2d4d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/src/auth/hooks/useCustomAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export function useCustomAuth(): {
[logout, userAuthorization, auth?.user?.profile?.email]
)

useEffect(
() =>
// the `return` is important - addAccessTokenExpiring() returns a cleanup function
auth?.events?.addAccessTokenExpiring(() => {
auth?.signinSilent()
}),
[auth]
)

useEffect(() => {
if (!auth) {
return
Expand All @@ -67,7 +76,7 @@ export function useCustomAuth(): {
const nextUserAuthorization = await getCurrentUserAuthorization()

setUserAuthorization(nextUserAuthorization)
}, 250)
}, 500)
}
}, [
auth,
Expand Down

0 comments on commit 5ca2d4d

Please sign in to comment.