- Remove session check from home page (landing page doesn't need it) - Add delayed session check in auth page to redirect logged-in users - Handle SuperTokens not being initialized yet with proper error handling Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import dynamic from "next/dynamic";
|
|
import { useEffect, useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
// Dynamically import SuperTokens component (client-side only)
|
|
const SuperTokensAuthComponent = dynamic(
|
|
() => import("@/app/components/SuperTokensAuthComponent"),
|
|
{ ssr: false }
|
|
);
|
|
|
|
export default function AuthPage() {
|
|
const router = useRouter();
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
|
|
// Check if already logged in after a short delay
|
|
setTimeout(async () => {
|
|
try {
|
|
const { doesSessionExist } = await import("supertokens-web-js/recipe/session");
|
|
const exists = await doesSessionExist();
|
|
if (exists) {
|
|
router.push("/marks-account/projects");
|
|
}
|
|
} catch (error) {
|
|
// SuperTokens not initialized yet, continue to show auth page
|
|
console.log("Session check skipped");
|
|
}
|
|
}, 500);
|
|
}, [router]);
|
|
|
|
if (!mounted) {
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-background">
|
|
<div className="text-center">
|
|
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent mx-auto mb-4" />
|
|
<p className="text-muted-foreground">Loading authentication...</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return <SuperTokensAuthComponent />;
|
|
}
|
|
|