Skip to content

Commit

Permalink
feat: enable more reliable timeout handling with nextauth (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterckx committed Oct 31, 2024
1 parent df97865 commit d603646
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/providers/nextAuthAuthentication/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NextAuthAuthenticationProviderProps } from "./types";

export function NextAuthAuthenticationProvider({
children,
refetchInterval = 0,
session,
timeout,
}: NextAuthAuthenticationProviderProps): JSX.Element {
Expand All @@ -23,6 +24,7 @@ export function NextAuthAuthenticationProvider({
const { isAuthenticated } = authState;
const { callbackUrl } = useSessionCallbackUrl();
useSessionIdleTimer({
crossTab: true,
disabled: !isAuthenticated,
onIdle: () => {
service.requestLogout({ callbackUrl, redirect: true });
Expand All @@ -31,7 +33,7 @@ export function NextAuthAuthenticationProvider({
});
useSessionAuth({ authReducer, authenticationReducer });
return (
<SessionProvider session={session}>
<SessionProvider session={session} refetchInterval={refetchInterval / 1000}>
<AuthenticationContext.Provider value={authenticationReducer}>
<AuthContext.Provider value={{ authDispatch, authState, service }}>
<SessionController>{children}</SessionController>
Expand Down
1 change: 1 addition & 0 deletions src/providers/nextAuthAuthentication/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReactNode } from "react";

export interface NextAuthAuthenticationProviderProps {
children: ReactNode | ReactNode[];
refetchInterval?: number;
session?: Session | null;
timeout?: number;
}

0 comments on commit d603646

Please sign in to comment.