Skip to content

Commit 3fe7820

Browse files
committed
fix(dashboard): add session validation guard to sign out stale sessions
The proxy only checks cookie presence — a revoked or expired session renders a broken dashboard with silenced auth errors. SessionGuard validates the session via useSession() and signs the user out if invalid.
1 parent 37859ea commit 3fe7820

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

apps/dashboard/app/(main)/layout.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FeedbackPrompt } from "@/components/feedback-prompt";
22
import { Sidebar } from "@/components/layout/sidebar";
33
import { SidebarNavigationProvider } from "@/components/layout/sidebar-navigation-provider";
44
import { BillingProvider } from "@/components/providers/billing-provider";
5+
import { SessionGuard } from "@/components/providers/session-guard";
56
import { CommandSearchProvider } from "@/components/ui/command-search";
67
import { AutumnProvider } from "autumn-js/react";
78
import { Suspense } from "react";
@@ -19,17 +20,19 @@ export default function MainLayout({
1920
<BillingProvider>
2021
<CommandSearchProvider>
2122
<SidebarNavigationProvider>
22-
<div className="flex min-h-0 flex-1 flex-col overflow-hidden text-foreground">
23-
<Suspense fallback={null}>
24-
<Sidebar />
25-
</Suspense>
26-
<div className="relative flex min-h-0 flex-1 flex-col pl-0 md:pl-76 lg:pl-84">
27-
<div className="flex min-h-0 flex-1 flex-col overflow-hidden overflow-x-hidden overscroll-none pt-12 md:pt-0">
28-
{children}
23+
<SessionGuard>
24+
<div className="flex min-h-0 flex-1 flex-col overflow-hidden text-foreground">
25+
<Suspense fallback={null}>
26+
<Sidebar />
27+
</Suspense>
28+
<div className="relative flex min-h-0 flex-1 flex-col pl-0 md:pl-76 lg:pl-84">
29+
<div className="flex min-h-0 flex-1 flex-col overflow-hidden overflow-x-hidden overscroll-none pt-12 md:pt-0">
30+
{children}
31+
</div>
2932
</div>
33+
<FeedbackPrompt />
3034
</div>
31-
<FeedbackPrompt />
32-
</div>
35+
</SessionGuard>
3336
</SidebarNavigationProvider>
3437
</CommandSearchProvider>
3538
</BillingProvider>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use client";
2+
3+
import { authClient } from "@databuddy/auth/client";
4+
import { useEffect } from "react";
5+
6+
export function SessionGuard({ children }: { children: React.ReactNode }) {
7+
const { data: session, isPending } = authClient.useSession();
8+
9+
useEffect(() => {
10+
if (isPending || session) {
11+
return;
12+
}
13+
14+
authClient.signOut().finally(() => {
15+
window.location.href = "/login";
16+
});
17+
}, [isPending, session]);
18+
19+
return <>{children}</>;
20+
}

0 commit comments

Comments
 (0)