'use client'; import Link from 'next/link'; import type { ReactNode } from 'react'; import { useMemo, useState } from 'react'; type Props = { token: string; languageSwitcher: ReactNode; resetRequest: { email: string; name: string; expiresAt: string | null; }; }; function passwordChecks(password: string) { return { minLength: password.length >= 8, hasNumber: /\d/.test(password), hasSpecial: /[^A-Za-z0-9]/.test(password), }; } function formatExpiry(value: string | null) { if (!value) return 'Unavailable'; return new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short', }).format(new Date(value)); } export function ResetPasswordCard({ token, resetRequest, languageSwitcher }: Props) { const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [message, setMessage] = useState(''); const [error, setError] = useState(''); const [pending, setPending] = useState(false); const checks = useMemo(() => passwordChecks(password), [password]); const strengthCount = [checks.minLength, checks.hasNumber, checks.hasSpecial].filter(Boolean).length; const strengthLabel = strengthCount <= 1 ? 'Weak' : strengthCount === 2 ? 'Medium' : 'Strong'; async function submit() { setError(''); setMessage(''); if (password !== confirmPassword) { setError('Password confirmation does not match.'); return; } setPending(true); try { const response = await fetch(`/api/auth/password-reset/${token}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }), }); const payload = await response.json(); if (!response.ok) { setError(payload.message || 'Failed to reset password'); return; } setMessage('Password updated. You can now log in with your new password.'); } finally { setPending(false); } } return (
password
verified_user
{languageSwitcher}
vpn_key

BizOne

Create a new password and secure the admin account before returning to the dashboard.

Reset Your Password

Hello, {resetRequest.name}. Choose a new password for {resetRequest.email}.

Reset link expires: {formatExpiry(resetRequest.expiresAt)}

Password Strength {strengthLabel}
{[0, 1, 2, 3].map((index) => ( ))}
{checks.minLength ? 'check_circle' : 'circle'} Minimum 8 characters
{checks.hasNumber ? 'check_circle' : 'circle'} At least one number
{checks.hasSpecial ? 'check_circle' : 'circle'} One special character (@, #, $, etc.)
{error ?

{error}

: null} {message ?

{message}

: null}
Need help? Back to login
); }