File tree Expand file tree Collapse file tree 2 files changed +32
-9
lines changed
Expand file tree Collapse file tree 2 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { FeedbackPrompt } from "@/components/feedback-prompt";
22import { Sidebar } from "@/components/layout/sidebar" ;
33import { SidebarNavigationProvider } from "@/components/layout/sidebar-navigation-provider" ;
44import { BillingProvider } from "@/components/providers/billing-provider" ;
5+ import { SessionGuard } from "@/components/providers/session-guard" ;
56import { CommandSearchProvider } from "@/components/ui/command-search" ;
67import { AutumnProvider } from "autumn-js/react" ;
78import { 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 >
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments