-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from Vizzuality/chore/expire-session
expiring session
- Loading branch information
Showing
8 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
|
||
import { PropsWithChildren, useEffect } from "react"; | ||
import { signOut, useSession } from "next-auth/react"; | ||
|
||
import { privatePaths } from "@/middleware"; | ||
import { usePathname } from "next/navigation"; | ||
|
||
export default function SessionChecker({ children }: PropsWithChildren) { | ||
const { data: sessionData } = useSession(); | ||
const pathname = usePathname(); | ||
|
||
useEffect(() => { | ||
if (!!sessionData?.error) { | ||
// Check if the current path is part of private paths | ||
const isPrivatePath = privatePaths.includes(pathname); | ||
|
||
// Sign out user and redirect them to signin page if needed | ||
signOut({ | ||
callbackUrl: isPrivatePath ? "/signin" : undefined, // Only add callbackUrl for private paths | ||
}); | ||
} | ||
}, [sessionData, pathname]); | ||
|
||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters