feat: add password visibility toggle and forgot password flow

Closes #11

Sign-in page improvements:
- Add show/hide password toggle with eye icons (inline SVG)
- Add "Forgot password?" link next to password label

New forgot-password page:
- Email input for password reset request
- Success state with confirmation message
- Calls /api/auth/forget-password endpoint
- Theme-aware styling for alerts

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ajax Davis 2026-01-07 13:56:00 +10:00
parent f519952441
commit 00908118b3
2 changed files with 203 additions and 12 deletions

View file

@ -0,0 +1,133 @@
'use client';
import Link from 'next/link';
import { useState } from 'react';
export default function ForgotPasswordPage() {
const [email, setEmail] = useState('');
const [error, setError] = useState('');
const [success, setSuccess] = useState(false);
const [loading, setLoading] = useState(false);
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setError('');
setLoading(true);
try {
// Call the password reset API endpoint
const response = await fetch('/api/auth/forget-password', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
redirectTo: `${window.location.origin}/reset-password`,
}),
});
if (!response.ok) {
const data = await response.json();
setError(data.message || 'Failed to send reset email');
setLoading(false);
return;
}
setSuccess(true);
setLoading(false);
} catch (err) {
console.error('Forgot password exception:', err);
setError('An unexpected error occurred');
setLoading(false);
}
}
if (success) {
return (
<div className="space-y-6">
<div className="text-center">
<h1 className="text-2xl font-bold text-foreground">Check Your Email</h1>
<p className="text-foreground-secondary mt-2">
If an account exists for <strong>{email}</strong>, we&apos;ve sent a password reset
link.
</p>
</div>
<div className="bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800 text-green-700 dark:text-green-300 px-4 py-3 rounded-md text-sm">
Check your inbox and click the link to reset your password. The link will expire in 1
hour.
</div>
<p className="text-center text-sm text-foreground-secondary">
Didn&apos;t receive the email?{' '}
<button
type="button"
onClick={() => {
setSuccess(false);
setEmail('');
}}
className="text-foreground hover:underline font-medium"
>
Try again
</button>
</p>
<p className="text-center text-sm text-foreground-secondary">
<Link href="/sign-in" className="text-foreground hover:underline font-medium">
Back to Sign In
</Link>
</p>
</div>
);
}
return (
<div className="space-y-6">
<div className="text-center">
<h1 className="text-2xl font-bold text-foreground">Reset Password</h1>
<p className="text-foreground-secondary mt-2">
Enter your email and we&apos;ll send you a reset link
</p>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
{error && (
<div className="bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 px-4 py-3 rounded-md text-sm">
{error}
</div>
)}
<div>
<label htmlFor="email" className="block text-sm font-medium text-foreground mb-1">
Email
</label>
<input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-foreground focus:border-transparent"
placeholder="you@example.com"
/>
</div>
<button
type="submit"
disabled={loading}
className="w-full py-2 px-4 bg-foreground text-background font-medium rounded-md hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-foreground disabled:opacity-50 disabled:cursor-not-allowed"
>
{loading ? 'Sending...' : 'Send Reset Link'}
</button>
</form>
<p className="text-center text-sm text-foreground-secondary">
Remember your password?{' '}
<Link href="/sign-in" className="text-foreground hover:underline font-medium">
Sign in
</Link>
</p>
</div>
);
}

View file

@ -4,9 +4,49 @@ import { signIn } from '@/lib/auth-client';
import Link from 'next/link';
import { useState } from 'react';
function EyeIcon({ className }: { className?: string }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={className || 'w-5 h-5'}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z"
/>
<path strokeLinecap="round" strokeLinejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>
);
}
function EyeOffIcon({ className }: { className?: string }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={className || 'w-5 h-5'}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3.98 8.223A10.477 10.477 0 0 0 1.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.451 10.451 0 0 1 12 4.5c4.756 0 8.773 3.162 10.065 7.498a10.522 10.522 0 0 1-4.293 5.774M6.228 6.228 3 3m3.228 3.228 3.65 3.65m7.894 7.894L21 21m-3.228-3.228-3.65-3.65m0 0a3 3 0 1 0-4.243-4.243m4.242 4.242L9.88 9.88"
/>
</svg>
);
}
export default function SignInPage() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
@ -88,18 +128,36 @@ export default function SignInPage() {
</div>
<div>
<label htmlFor="password" className="block text-sm font-medium text-foreground mb-1">
Password
</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
className="w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-foreground focus:border-transparent"
placeholder="Enter your password"
/>
<div className="flex items-center justify-between mb-1">
<label htmlFor="password" className="block text-sm font-medium text-foreground">
Password
</label>
<Link
href="/forgot-password"
className="text-sm text-foreground-secondary hover:text-foreground hover:underline"
>
Forgot password?
</Link>
</div>
<div className="relative">
<input
id="password"
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e) => setPassword(e.target.value)}
required
className="w-full px-3 py-2 pr-10 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-foreground focus:border-transparent"
placeholder="Enter your password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-foreground-tertiary hover:text-foreground transition-colors"
aria-label={showPassword ? 'Hide password' : 'Show password'}
>
{showPassword ? <EyeOffIcon className="w-4 h-4" /> : <EyeIcon className="w-4 h-4" />}
</button>
</div>
</div>
<button