diff --git a/www/app/(auth)/userInfo.tsx b/www/app/(auth)/userInfo.tsx index f9725a13..2141789a 100644 --- a/www/app/(auth)/userInfo.tsx +++ b/www/app/(auth)/userInfo.tsx @@ -2,13 +2,19 @@ import { Spinner, Link } from "@chakra-ui/react"; import { useAuth } from "../lib/AuthProvider"; +import { usePathname } from "next/navigation"; +import { getLogoutRedirectUrl } from "../lib/auth"; export default function UserInfo() { const auth = useAuth(); + const pathname = usePathname(); const status = auth.status; const isLoading = status === "loading"; const isAuthenticated = status === "authenticated"; const isRefreshing = status === "refreshing"; + + const callbackUrl = getLogoutRedirectUrl(pathname); + return isLoading ? ( ) : !isAuthenticated && !isRefreshing ? ( @@ -26,7 +32,7 @@ export default function UserInfo() { auth.signOut({ callbackUrl: "/" })} + onClick={() => auth.signOut({ callbackUrl })} > Log out diff --git a/www/app/lib/auth.ts b/www/app/lib/auth.ts index e562eaed..cacc80ec 100644 --- a/www/app/lib/auth.ts +++ b/www/app/lib/auth.ts @@ -18,3 +18,8 @@ export const LOGIN_REQUIRED_PAGES = [ export const PROTECTED_PAGES = new RegExp( LOGIN_REQUIRED_PAGES.map((page) => `^${page}$`).join("|"), ); + +export function getLogoutRedirectUrl(pathname: string): string { + const transcriptPagePattern = /^\/transcripts\/[^/]+$/; + return transcriptPagePattern.test(pathname) ? pathname : "/"; +}