fix: type fix

This commit is contained in:
gosangam
2026-06-02 19:38:23 +05:30
parent b61c3df473
commit 086f1dd8aa
2 changed files with 31 additions and 20 deletions
+21 -11
View File
@@ -14,7 +14,7 @@
* would just no-op).
*/
import { useEffect } from "react";
import { Suspense, useEffect } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { useAuth } from "@/components/auth/auth-provider";
@@ -23,6 +23,24 @@ export default function AuthLayout({
}: {
children: React.ReactNode;
}) {
// useSearchParams forces a CSR bailout during prerender, so Next.js
// requires a Suspense boundary anywhere it's read. The gate is the
// only consumer here — isolate it so the rest of the layout can still
// SSR normally.
return (
<main className="flex items-center justify-center px-4 py-12 min-h-[90vh]">
<Suspense fallback={<AuthShell>{children}</AuthShell>}>
<AuthGate>{children}</AuthGate>
</Suspense>
</main>
);
}
function AuthShell({ children }: { children: React.ReactNode }) {
return <div className="w-full max-w-md">{children}</div>;
}
function AuthGate({ children }: { children: React.ReactNode }) {
const { user, loading } = useAuth();
const router = useRouter();
const params = useSearchParams();
@@ -35,16 +53,8 @@ export default function AuthLayout({
// Don't flash the form for an instant before the redirect fires.
if (!loading && user) {
return (
<main className="flex items-center justify-center px-4 py-12 min-h-[90vh]">
<p className="text-sm text-muted-foreground">Redirecting…</p>
</main>
);
return <p className="text-sm text-muted-foreground">Redirecting…</p>;
}
return (
<main className="flex items-center justify-center px-4 py-12 min-h-[90vh]">
<div className="w-full max-w-md">{children}</div>
</main>
);
return <AuthShell>{children}</AuthShell>;
}