SurfSense/surfsense_web/app/dashboard/layout.tsx

39 lines
972 B
TypeScript
Raw Normal View History

2025-06-09 15:50:15 -07:00
"use client";
2026-01-26 23:32:30 -08:00
import { useEffect, useState } from "react";
import { useGlobalLoadingEffect } from "@/hooks/use-global-loading";
import { getBearerToken, redirectToLogin } from "@/lib/auth-utils";
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 [isCheckingAuth, setIsCheckingAuth] = useState(true);
2025-06-09 15:50:15 -07:00
// Use the global loading screen - spinner animation won't reset
2026-01-27 15:28:30 +05:30
useGlobalLoadingEffect(isCheckingAuth);
2025-07-27 10:05:37 -07:00
useEffect(() => {
// Check if user is authenticated
const token = getBearerToken();
2025-07-27 10:05:37 -07:00
if (!token) {
// Save current path and redirect to login
redirectToLogin();
2025-07-27 10:05:37 -07:00
return;
}
setIsCheckingAuth(false);
}, []);
2025-06-09 15:50:15 -07:00
// Return null while loading - the global provider handles the loading UI
if (isCheckingAuth) {
return null;
2025-07-27 10:05:37 -07:00
}
2025-06-09 15:50:15 -07:00
return (
2025-11-11 04:02:04 +02:00
<div className="h-full flex flex-col ">
<div className="flex-1 min-h-0">{children}</div>
</div>
);
2025-07-27 10:05:37 -07:00
}