fix(build): read URL params via window in guards (avoid useSearchParams prerender error)
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
@@ -1,23 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { authApi } from '@/lib/api';
|
||||
|
||||
type Status = 'checking' | { kind: 'ok'; guestName: string } | 'denied';
|
||||
|
||||
export default function GuestGuard({ children }: { children: React.ReactNode }) {
|
||||
const params = useSearchParams();
|
||||
const [status, setStatus] = useState<Status>('checking');
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
const usr = params.get('usr');
|
||||
const usr = new URL(window.location.href).searchParams.get('usr');
|
||||
try {
|
||||
if (usr) {
|
||||
await authApi.session({ usr });
|
||||
// user said leaving the token in URL is fine — do NOT strip
|
||||
}
|
||||
const who = await authApi.whoami();
|
||||
if (cancelled) return;
|
||||
@@ -31,7 +28,7 @@ export default function GuestGuard({ children }: { children: React.ReactNode })
|
||||
}
|
||||
})();
|
||||
return () => { cancelled = true; };
|
||||
}, [params]);
|
||||
}, []);
|
||||
|
||||
if (status === 'checking') return <div className="min-h-screen flex items-center justify-center text-gray-500">Verificando convite…</div>;
|
||||
if (status === 'denied') return <div className="min-h-screen flex items-center justify-center text-center px-6">
|
||||
|
||||
Reference in New Issue
Block a user