diff --git a/src/app/(unauth)/login/page.tsx b/src/app/(unauth)/login/page.tsx index aa50bf1..cb92f06 100644 --- a/src/app/(unauth)/login/page.tsx +++ b/src/app/(unauth)/login/page.tsx @@ -6,6 +6,9 @@ import { useFormState, useFormStatus } from "react-dom"; import { login, LoginUserData } from "@/app/actions"; import { useEffect } from "react"; import { useRouter } from "next/navigation"; +import { validateAuth } from "@/lib/api"; +import { useSuspenseQuery } from "@tanstack/react-query"; +import { LoaderCircleIcon } from "lucide-react"; const initialState: { email?: string; @@ -17,15 +20,34 @@ const initialState: { export default function Login() { const [state, formAction] = useFormState(login, initialState); const { pending } = useFormStatus(); + const { data: isLoggedIn, isLoading, refetch } = useSuspenseQuery(validateAuth); const router = useRouter(); + // const checkAuth = async () => {}; + + useEffect(() => { + console.log("[auth]", { isLoggedIn, isLoading }); + if (!isLoading && isLoggedIn) { + // redirect to auth page + router.push("/"); + } + }, [isLoggedIn, isLoading, router]); useEffect(() => { if (state.user) { - router.push('/'); + // router.push('/'); + window.location.reload(); } }, [router, state.user]) + if (isLoading) { + return ( +
+ +
+ ); + } + return (
diff --git a/src/components/custom/LayoutPanel.tsx b/src/components/custom/LayoutPanel.tsx index 4b8a1c3..2687427 100644 --- a/src/components/custom/LayoutPanel.tsx +++ b/src/components/custom/LayoutPanel.tsx @@ -25,7 +25,7 @@ export default function LayoutPanel({ children }: PropsWithChildren) { if (!isLoading && !isLoggedIn) { console.log("[auth]", { isLoggedIn }); // redirect to auth page - router.push('/login') + // router.push('/login') } }, [isLoggedIn, isLoading, router]);