2025-06-09 15:50:15 -07:00
|
|
|
"use client";
|
|
|
|
|
|
2025-07-27 10:54:25 -07:00
|
|
|
import { useEffect, useState } from "react";
|
2026-01-24 19:42:07 +05:30
|
|
|
import { useTranslations } from "next-intl";
|
|
|
|
|
import { UnifiedLoadingScreen } from "@/components/ui/unified-loading-screen";
|
2025-12-02 01:24:09 -08:00
|
|
|
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) {
|
2026-01-24 19:42:07 +05:30
|
|
|
const t = useTranslations("dashboard");
|
2025-07-27 10:05:37 -07:00
|
|
|
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
|
2025-12-02 01:24:09 -08:00
|
|
|
const token = getBearerToken();
|
2025-07-27 10:05:37 -07:00
|
|
|
if (!token) {
|
2025-12-02 01:24:09 -08:00
|
|
|
// Save current path and redirect to login
|
|
|
|
|
redirectToLogin();
|
2025-07-27 10:05:37 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setIsCheckingAuth(false);
|
2025-12-02 01:24:09 -08:00
|
|
|
}, []);
|
2025-06-09 15:50:15 -07:00
|
|
|
|
2025-10-10 00:50:29 -07:00
|
|
|
// Show loading screen while checking authentication
|
|
|
|
|
if (isCheckingAuth) {
|
2026-01-24 19:42:07 +05:30
|
|
|
return <UnifiedLoadingScreen variant="default" message={t("checking_auth")} />;
|
2025-07-27 10:05:37 -07:00
|
|
|
}
|
2025-06-09 15:50:15 -07:00
|
|
|
|
2025-11-03 22:34:37 -08: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-11-03 22:34:37 -08:00
|
|
|
);
|
2025-07-27 10:05:37 -07:00
|
|
|
}
|