2026-06-16 01:39:32 +05:30
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { USER_QUERY_KEY } from "@/atoms/user/user-query.atoms";
|
|
|
|
|
import { useGlobalLoadingEffect } from "@/hooks/use-global-loading";
|
2026-06-23 13:01:41 +05:30
|
|
|
import { useSession } from "@/hooks/use-session";
|
2026-06-24 03:55:40 +05:30
|
|
|
import { redirectToLogin } from "@/lib/auth-utils";
|
2026-06-16 01:39:32 +05:30
|
|
|
import { queryClient } from "@/lib/query-client/client";
|
|
|
|
|
|
|
|
|
|
export function DashboardShell({ children }: { children: React.ReactNode }) {
|
|
|
|
|
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
|
2026-06-23 13:01:41 +05:30
|
|
|
const session = useSession();
|
2026-06-16 01:39:32 +05:30
|
|
|
|
|
|
|
|
// Use the global loading screen - spinner animation won't reset
|
|
|
|
|
useGlobalLoadingEffect(isCheckingAuth);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function checkAuth() {
|
2026-06-23 13:01:41 +05:30
|
|
|
if (session.status === "loading") return;
|
|
|
|
|
if (session.status === "unauthenticated") {
|
2026-06-16 01:39:32 +05:30
|
|
|
redirectToLogin();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: [...USER_QUERY_KEY] });
|
|
|
|
|
setIsCheckingAuth(false);
|
|
|
|
|
}
|
2026-06-23 13:01:41 +05:30
|
|
|
void checkAuth();
|
|
|
|
|
}, [session.status]);
|
2026-06-16 01:39:32 +05:30
|
|
|
|
|
|
|
|
// Return null while loading - the global provider handles the loading UI
|
|
|
|
|
if (isCheckingAuth) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="h-full flex flex-col ">
|
|
|
|
|
<div className="flex-1 min-h-0">{children}</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|