"use client"; import { Suspense, useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import Header from "@/components/Header"; import Footer from "@/components/Footer"; import { createClient } from "@/lib/supabase/client"; function ResetInner() { const router = useRouter(); const supabase = createClient(); const [hasSession, setHasSession] = useState(null); const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [busy, setBusy] = useState(false); const [msg, setMsg] = useState(null); const [err, setErr] = useState(null); // The recovery flow lands here with a fresh session (Supabase verifies // the token in the URL hash and signs the user in). Confirm we got it. useEffect(() => { supabase.auth.getSession().then(({ data }) => { setHasSession(!!data.session); }); }, [supabase]); async function submit(e: React.FormEvent) { e.preventDefault(); setBusy(true); setMsg(null); setErr(null); if (password.length < 8) { setErr("Use at least 8 characters."); setBusy(false); return; } if (password !== confirm) { setErr("Passwords don't match."); setBusy(false); return; } const { error } = await supabase.auth.updateUser({ password }); setBusy(false); if (error) { setErr(error.message); return; } setMsg("Password updated. Redirecting…"); setTimeout(() => router.push("/forum"), 1200); } return ( <>
Reset password

Set a new password

{hasSession === false ? (

This reset link is expired or invalid.

Request a new link
) : (
{err && (
{err}
)} {msg && (
{msg}
)}
setPassword(e.target.value)} autoComplete="new-password" minLength={8} required className="w-full bg-[#0d0d0d] border border-[#2a2a2a] rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-[#3b82f6]" />
setConfirm(e.target.value)} autoComplete="new-password" required className="w-full bg-[#0d0d0d] border border-[#2a2a2a] rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-[#3b82f6]" />
)}