import { getI18n } from "@/lib/i18n"; import { cookies } from "next/headers"; import Link from "next/link"; import { Header, Footer } from "@/components/Shell"; import { PasswordForm } from "@/components/PasswordForm"; import { authClient, rawUser } from "@/lib/supabase"; import { recoveryCookie, verifyRecoveryGrant } from "@/lib/password-recovery"; export async function generateMetadata() { const { t } = await getI18n(); return { title: t("Reset password") }; } export default async function ResetPassword() { const { t } = await getI18n(); const [account, jar, client] = await Promise.all([ rawUser(), cookies(), authClient(), ]); const { data } = account ? await client.auth.getClaims() : { data: null }; const sessionId = data?.claims.session_id; const valid = account && typeof sessionId === "string" && verifyRecoveryGrant( jar.get(recoveryCookie)?.value, account.id, sessionId, process.env.SUPABASE_SECRET_KEY!, ); return ( <>
{t("ACCOUNT RECOVERY")}

{t("A fresh start.")}

{valid ? ( <>

{t("Choose a new password for your account.")}

) : ( <>

{t( "This reset link has expired or has already been used. Request a fresh link to continue.", )}

{t("Request a new reset link →")} )}