import { cookies } from 'next/headers'; import { redirect } from 'next/navigation'; import { resetCookieName } from '@/core/lib/auth-cookie'; import { ResetPasswordForm } from './reset-password-form'; /** * The email Brainerce sends links to `/reset-password?token=...`. * That token must never reach client JavaScript, so this server component hands * it to `/api/auth/reset-callback`, which stores it in an httpOnly cookie and * returns here with a clean URL. The form then posts the new password through * `/api/auth/reset-password`, which reads the cookie server-side. * * Without this hop the page rendered with no cookie and every reset failed with * "No reset token found", because the callback route was only ever reached by a * `resetUrl` option the SDK does not send. */ export default async function ResetPasswordPage({ searchParams, }: { searchParams: Promise<{ token?: string }>; }) { const { token } = await searchParams; if (token) { redirect(`/api/auth/reset-callback?token=${encodeURIComponent(token)}`); } // No link was opened and no token is waiting in the cookie (a bare /reset-password, an expired // cookie, a malformed link the callback refused): say so instead of showing a form that cannot work. const hasResetToken = !!(await cookies()).get(resetCookieName())?.value; return ; }