Skip to content

Commit

Permalink
fix: timeout max 24days bug and redirect outside of timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
SeDemal committed Apr 24, 2024
1 parent 7796b0e commit ab10e0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/components/layout/header/AvatarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -65,12 +65,15 @@ export const AvatarMenu = () => {
<Menu.Item
icon={<IconLogout size="1rem" />}
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,
Expand Down
2 changes: 1 addition & 1 deletion src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/custom-session-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -21,4 +21,4 @@ export const CustomSessionProvider = ({ session, children }: CustomSessionProvid
{children}
</SessionProvider>
);
};
};

0 comments on commit ab10e0f

Please sign in to comment.