-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellLayout.tsx
More file actions
40 lines (31 loc) · 1015 Bytes
/
ShellLayout.tsx
File metadata and controls
40 lines (31 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use client";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";
import { AppShell } from "@/components/AppShell";
import { useAuth } from "@/contexts/auth";
const PUBLIC_PATHS = new Set(["/", "/login", "/register", "/auth/callback"]);
export function ShellLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const { user, loading } = useAuth();
const router = useRouter();
const isPublic = PUBLIC_PATHS.has(pathname);
useEffect(() => {
if (!loading && !user && !isPublic) {
router.replace("/login");
}
}, [loading, user, isPublic, router]);
if (isPublic) {
return <>{children}</>;
}
if (loading) {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="h-6 w-6 animate-spin rounded-full border-2 border-teal-600 border-t-transparent" />
</div>
);
}
if (!user) {
return null;
}
return <AppShell>{children}</AppShell>;
}