From 49739508fbe0dd7e2de40d47747262f6bfb173fe Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 13 Aug 2024 16:10:03 +0200 Subject: [PATCH] Add silent renew --- frontend/src/auth/hooks/useCustomAuth.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/auth/hooks/useCustomAuth.tsx b/frontend/src/auth/hooks/useCustomAuth.tsx index 1c44b7e41a..0aad791731 100644 --- a/frontend/src/auth/hooks/useCustomAuth.tsx +++ b/frontend/src/auth/hooks/useCustomAuth.tsx @@ -39,6 +39,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 @@ -61,7 +70,7 @@ export function useCustomAuth(): { const nextUserAuthorization = await getCurrentUserAuthorization() setUserAuthorization(nextUserAuthorization) - }, 250) + }, 500) } }, [ auth,