From ab10e0f29fe8360de438d76fa22ae9a7265fddfa Mon Sep 17 00:00:00 2001 From: Tagaishi Date: Wed, 24 Apr 2024 18:33:27 +0200 Subject: [PATCH] fix: timeout max 24days bug and redirect outside of timeout --- src/components/layout/header/AvatarMenu.tsx | 15 +++++++++------ src/env.js | 2 +- src/hooks/custom-session-provider.tsx | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/layout/header/AvatarMenu.tsx b/src/components/layout/header/AvatarMenu.tsx index 9686518bcdd..00e1fa94457 100644 --- a/src/components/layout/header/AvatarMenu.tsx +++ b/src/components/layout/header/AvatarMenu.tsx @@ -14,9 +14,9 @@ import { signOut, useSession } from 'next-auth/react'; import { useTranslation } from 'next-i18next'; import Link from 'next/link'; import { forwardRef } from 'react'; +import { env } from '~/env'; import { useColorScheme } from '~/hooks/use-colorscheme'; -import { env } from '~/env'; import { useBoardLink } from '../Templates/BoardLayout'; export const AvatarMenu = () => { @@ -65,12 +65,15 @@ export const AvatarMenu = () => { } color="red" - onClick={() => + onClick={() => { signOut({ - callbackUrl: env.NEXT_PUBLIC_LOGOUT_REDIRECT_URL ?? "/", - redirect: env.NEXT_PUBLIC_LOGOUT_REDIRECT_URL != undefined, - }).then(() => window.location.reload()) - } + redirect: false, + }).then(() => + env.NEXT_PUBLIC_LOGOUT_REDIRECT_URL + ? window.location.assign(env.NEXT_PUBLIC_LOGOUT_REDIRECT_URL) + : window.location.reload() + ); + }} > {t('actions.avatar.logout', { username: sessionData.user.name, diff --git a/src/env.js b/src/env.js index eb75bd0640d..67753a6e36e 100644 --- a/src/env.js +++ b/src/env.js @@ -164,7 +164,7 @@ const env = createEnv({ AUTH_OIDC_AUTO_LOGIN: process.env.AUTH_OIDC_AUTO_LOGIN, AUTH_OIDC_SCOPE_OVERWRITE: process.env.AUTH_OIDC_SCOPE_OVERWRITE, AUTH_OIDC_TIMEOUT: process.env.AUTH_OIDC_TIMEOUT, - NEXT_PUBLIC_LOGOUT_REDIRECT_URL: process.env.AUTH_OIDC_REDIRECT_LOGOUT_URL, + NEXT_PUBLIC_LOGOUT_REDIRECT_URL: process.env.NEXT_PUBLIC_LOGOUT_REDIRECT_URL, AUTH_SESSION_EXPIRY_TIME: process.env.AUTH_SESSION_EXPIRY_TIME, DEMO_MODE: process.env.DEMO_MODE, }, diff --git a/src/hooks/custom-session-provider.tsx b/src/hooks/custom-session-provider.tsx index e9a89a4884d..aa12b13a807 100644 --- a/src/hooks/custom-session-provider.tsx +++ b/src/hooks/custom-session-provider.tsx @@ -9,10 +9,10 @@ interface CustomSessionProviderProps { } export const CustomSessionProvider = ({ session, children }: CustomSessionProviderProps) => { - //Automatically redirect to the login page after a session expires + //Automatically redirect to the login page after a session expires or after 24 days useEffect(() => { if (!session) return () => {}; - const timeout = setTimeout(signIn, dayjs(session?.expires).diff()); + const timeout = setTimeout(signIn, Math.min(dayjs(session.expires).diff(), 2147483647)); return () => clearTimeout(timeout); }, [session]); @@ -21,4 +21,4 @@ export const CustomSessionProvider = ({ session, children }: CustomSessionProvid {children} ); -}; +}; \ No newline at end of file