1"use client";
2
3import { useEffect } from "react";
4import { useRouter } from "next/navigation";
5import { useAuth } from "@/hooks/use-auth";
6import { WorkspaceShell } from "@/components/layout/workspace-shell";
7
8
13export default function AppLayout({ children }: { children: React.ReactNode }) {
14 const { user, initializing } = useAuth();
15 const router = useRouter();
16
17 useEffect(() => {
18 if (!initializing && !user) {
19 const next = window.location.pathname + window.location.search;
20 router.replace(`/login?next=${encodeURIComponent(next)}`);
21 }
22 }, [initializing, user, router]);
23
24 if (initializing || !user) {
25 return (
26 <div className="flex min-h-screen items-center justify-center bg-background">
27 <div className="flex items-center gap-3 text-sm text-muted-foreground" role="status">
28 <span className="size-4 animate-spin rounded-full border-2 border-muted-foreground/30 border-t-foreground" />
29 Loading workspace…
30 </div>
31 </div>
32 );
33 }
34
35 return <WorkspaceShell>{children}</WorkspaceShell>;
36}
37