SurfSense/surfsense_web/app/dashboard/layout.tsx

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-06-09 15:50:15 -07:00
"use client";
2025-07-27 10:05:37 -07:00
import { Loader2 } from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
2025-07-27 10:05:37 -07:00
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
2025-06-09 15:50:15 -07:00
interface DashboardLayoutProps {
2025-07-27 10:05:37 -07:00
children: React.ReactNode;
2025-06-09 15:50:15 -07:00
}
export default function DashboardLayout({ children }: DashboardLayoutProps) {
2025-07-27 10:05:37 -07:00
const router = useRouter();
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
2025-06-09 15:50:15 -07:00
2025-07-27 10:05:37 -07:00
useEffect(() => {
// Check if user is authenticated
const token = localStorage.getItem("surfsense_bearer_token");
if (!token) {
router.push("/login");
return;
}
setIsCheckingAuth(false);
}, [router]);
2025-06-09 15:50:15 -07:00
// Show loading screen while checking authentication
if (isCheckingAuth) {
2025-07-27 10:05:37 -07:00
return (
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
<Card className="w-[350px] bg-background/60 backdrop-blur-sm">
<CardHeader className="pb-2">
<CardTitle className="text-xl font-medium">Loading Dashboard</CardTitle>
<CardDescription>Checking authentication...</CardDescription>
2025-07-27 10:05:37 -07:00
</CardHeader>
<CardContent className="flex justify-center py-6">
<Loader2 className="h-12 w-12 text-primary animate-spin" />
</CardContent>
</Card>
</div>
);
}
2025-06-09 15:50:15 -07:00
return <>{children}</>;
2025-07-27 10:05:37 -07:00
}