SurfSense/surfsense_web/app/dashboard/layout.tsx
Ojārs Kapteinis 28f2076141 Fix translation keys, session persistence, and add admin tools
- Fix nav_menu translation key: 'Add Webpage(s)' -> 'Add Webpages'
- Fix session persistence: sync baseApiService token on login/logout/load
- Add admin user update script (scripts/update_admin_user.py)
- Add Ollama memory optimization guide

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 21:01:28 +02:00

54 lines
1.7 KiB
TypeScript

"use client";
import { Loader2 } from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { AnnouncementBanner } from "@/components/announcement-banner";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { baseApiService } from "@/lib/apis/base-api.service";
interface DashboardLayoutProps {
children: React.ReactNode;
}
export default function DashboardLayout({ children }: DashboardLayoutProps) {
const router = useRouter();
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
useEffect(() => {
// Check if user is authenticated
const token = localStorage.getItem("surfsense_bearer_token");
if (!token) {
router.push("/login");
return;
}
// Ensure the baseApiService has the correct token
// This handles cases where the page is refreshed or navigated to directly
baseApiService.setBearerToken(token);
setIsCheckingAuth(false);
}, [router]);
// Show loading screen while checking authentication
if (isCheckingAuth) {
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>
</CardHeader>
<CardContent className="flex justify-center py-6">
<Loader2 className="h-12 w-12 text-primary animate-spin" />
</CardContent>
</Card>
</div>
);
}
return (
<div className="h-full flex flex-col ">
<AnnouncementBanner />
<div className="flex-1 min-h-0">{children}</div>
</div>
);
}