'use client'; import Link from 'next/link'; import { useRouter, useSearchParams } from 'next/navigation'; import { Suspense, useState } from 'react'; import type { MeDTO } from '@musicshare/shared'; import { api, useMe } from '@/lib/api'; export default function ResetPasswordPage() { return ( ); } function ResetPassword() { const token = useSearchParams().get('token'); const router = useRouter(); const { mutate } = useMe(); const [show, setShow] = useState(false); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); if (!token) { return (

Link incomplete

This reset link is missing part of its address. Open it straight from the email, or ask for a new one.

Send a new link
); } const onSubmit = async (e: React.FormEvent) => { e.preventDefault(); const password = String(new FormData(e.currentTarget).get('password') ?? ''); setBusy(true); setError(null); try { const { user } = await api<{ user: MeDTO }>('/auth/reset-password', { body: { token, password } }); await mutate(user, { revalidate: false }); router.replace('/'); } catch (err) { setError((err as Error).message); setBusy(false); } }; return (

Choose a new password

{error && (

{error} {error.includes('expired') && Send a new link}

)}

This signs you out on your other devices.

); }