2025-07-23 22:26:54 -04:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { useRouter } from 'next/router';
|
2025-07-28 12:09:58 -04:00
|
|
|
import Link from 'next/link';
|
2025-07-25 12:28:04 -04:00
|
|
|
import AuthLayout from '../components/AuthLayout';
|
2025-07-28 11:08:24 -04:00
|
|
|
import AnimatedFireLogo from '../components/AnimatedFireLogo';
|
2026-05-29 10:57:46 -04:00
|
|
|
import { VOCAB } from '../lib/collection-vocabulary.js';
|
2025-07-23 22:26:54 -04:00
|
|
|
|
|
|
|
|
export default function Login() {
|
|
|
|
|
const router = useRouter();
|
2025-07-24 17:36:10 -04:00
|
|
|
const [formData, setFormData] = useState({
|
|
|
|
|
email: '',
|
|
|
|
|
password: ''
|
|
|
|
|
});
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [error, setError] = useState('');
|
|
|
|
|
|
|
|
|
|
const handleInputChange = (field, value) => {
|
|
|
|
|
setFormData(prev => ({
|
|
|
|
|
...prev,
|
|
|
|
|
[field]: value
|
|
|
|
|
}));
|
|
|
|
|
// Clear error when user starts typing
|
|
|
|
|
if (error) setError('');
|
|
|
|
|
};
|
2025-07-23 22:26:54 -04:00
|
|
|
|
|
|
|
|
const handleSubmit = async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setLoading(true);
|
2025-07-24 17:36:10 -04:00
|
|
|
setError('');
|
2025-07-23 22:26:54 -04:00
|
|
|
|
|
|
|
|
try {
|
2025-07-24 17:36:10 -04:00
|
|
|
const response = await fetch('/api/auth/login', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(formData)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
2025-07-23 22:26:54 -04:00
|
|
|
|
2025-07-24 17:36:10 -04:00
|
|
|
if (response.ok) {
|
|
|
|
|
// Store the JWT token in localStorage
|
|
|
|
|
localStorage.setItem('auth_token', data.token);
|
|
|
|
|
|
|
|
|
|
// Redirect to admin panel or dashboard
|
|
|
|
|
if (data.user.role === 'admin') {
|
|
|
|
|
router.push('/admin/card-editor');
|
|
|
|
|
} else {
|
|
|
|
|
router.push('/dashboard');
|
|
|
|
|
}
|
2025-07-23 22:26:54 -04:00
|
|
|
} else {
|
2025-07-24 17:36:10 -04:00
|
|
|
setError(data.error || 'Login failed');
|
2025-07-23 22:26:54 -04:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2025-07-24 17:36:10 -04:00
|
|
|
console.error('Login error:', error);
|
|
|
|
|
setError('Network error. Please try again.');
|
2025-07-23 22:26:54 -04:00
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-25 11:47:09 -04:00
|
|
|
const handleQuickLogin = (email, password) => {
|
|
|
|
|
setFormData({ email, password });
|
2025-07-24 17:36:10 -04:00
|
|
|
};
|
|
|
|
|
|
2025-07-23 22:26:54 -04:00
|
|
|
return (
|
2025-07-25 12:28:04 -04:00
|
|
|
<AuthLayout>
|
2025-07-24 17:36:10 -04:00
|
|
|
<div className="min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
|
|
|
|
<div className="max-w-md w-full space-y-8">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="text-center">
|
2025-07-28 11:08:24 -04:00
|
|
|
<div className="mb-6 flex justify-center">
|
|
|
|
|
<AnimatedFireLogo size={100} />
|
|
|
|
|
</div>
|
2025-07-28 10:51:39 -04:00
|
|
|
<h2 className="text-3xl font-bold gradient-text-flame mb-2">
|
|
|
|
|
Welcome to Deck Hearth
|
2025-07-24 17:36:10 -04:00
|
|
|
</h2>
|
|
|
|
|
<p className="mt-2 text-sm" style={{ color: 'var(--text-secondary)' }}>
|
2026-05-29 10:57:46 -04:00
|
|
|
Sign in to access {VOCAB.MY_COLLECTION}
|
2025-07-24 17:36:10 -04:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-07-23 22:26:54 -04:00
|
|
|
|
2025-07-28 10:51:39 -04:00
|
|
|
<div
|
|
|
|
|
className="p-8 rounded-2xl shadow-2xl backdrop-blur-sm border border-opacity-20"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'rgba(var(--bg-secondary-rgb), 0.85)',
|
|
|
|
|
borderColor: 'var(--border)'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-07-24 17:36:10 -04:00
|
|
|
<form onSubmit={handleSubmit} className="space-y-6">
|
|
|
|
|
{error && (
|
2025-07-28 10:51:39 -04:00
|
|
|
<div className="p-4 rounded-lg bg-red-500 bg-opacity-10 border border-red-500 border-opacity-20 backdrop-blur-sm">
|
|
|
|
|
<p className="text-red-400 text-sm">{error}</p>
|
2025-07-24 17:36:10 -04:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-07-23 22:26:54 -04:00
|
|
|
|
2025-07-24 17:36:10 -04:00
|
|
|
<div>
|
|
|
|
|
<label htmlFor="email" className="block text-sm font-medium mb-2" style={{ color: 'var(--text-primary)' }}>
|
|
|
|
|
Email Address
|
|
|
|
|
</label>
|
2025-07-23 22:26:54 -04:00
|
|
|
<input
|
|
|
|
|
id="email"
|
|
|
|
|
name="email"
|
|
|
|
|
type="email"
|
|
|
|
|
autoComplete="email"
|
|
|
|
|
required
|
2025-07-24 17:36:10 -04:00
|
|
|
value={formData.email}
|
|
|
|
|
onChange={(e) => handleInputChange('email', e.target.value)}
|
2025-07-28 10:51:39 -04:00
|
|
|
className="w-full px-4 py-3 rounded-lg border transition-all duration-200 focus:ring-2 focus:ring-orange-500 focus:border-transparent backdrop-blur-sm"
|
2025-07-24 17:36:10 -04:00
|
|
|
style={{
|
2025-07-28 10:51:39 -04:00
|
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)',
|
2025-07-24 17:36:10 -04:00
|
|
|
borderColor: 'var(--border)',
|
|
|
|
|
color: 'var(--text-primary)'
|
|
|
|
|
}}
|
2025-07-23 22:26:54 -04:00
|
|
|
placeholder="Enter your email"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-07-24 17:36:10 -04:00
|
|
|
<div>
|
|
|
|
|
<label htmlFor="password" className="block text-sm font-medium mb-2" style={{ color: 'var(--text-primary)' }}>
|
|
|
|
|
Password
|
|
|
|
|
</label>
|
2025-07-23 22:26:54 -04:00
|
|
|
<input
|
|
|
|
|
id="password"
|
|
|
|
|
name="password"
|
|
|
|
|
type="password"
|
|
|
|
|
autoComplete="current-password"
|
|
|
|
|
required
|
2025-07-24 17:36:10 -04:00
|
|
|
value={formData.password}
|
|
|
|
|
onChange={(e) => handleInputChange('password', e.target.value)}
|
2025-07-28 10:51:39 -04:00
|
|
|
className="w-full px-4 py-3 rounded-lg border transition-all duration-200 focus:ring-2 focus:ring-orange-500 focus:border-transparent backdrop-blur-sm"
|
2025-07-24 17:36:10 -04:00
|
|
|
style={{
|
2025-07-28 10:51:39 -04:00
|
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)',
|
2025-07-24 17:36:10 -04:00
|
|
|
borderColor: 'var(--border)',
|
|
|
|
|
color: 'var(--text-primary)'
|
|
|
|
|
}}
|
2025-07-23 22:26:54 -04:00
|
|
|
placeholder="Enter your password"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-07-24 17:36:10 -04:00
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
disabled={loading}
|
|
|
|
|
className={`w-full px-4 py-3 rounded-lg font-medium transition-all duration-200 ${
|
|
|
|
|
loading
|
|
|
|
|
? 'opacity-50 cursor-not-allowed'
|
2025-07-28 10:51:39 -04:00
|
|
|
: 'gradient-bg-ember text-white hover:shadow-xl transform hover:scale-105 hover:shadow-orange-500/20'
|
2025-07-24 17:36:10 -04:00
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{loading ? (
|
|
|
|
|
<div className="flex items-center justify-center">
|
|
|
|
|
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"></div>
|
|
|
|
|
Signing in...
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
2025-07-28 10:51:39 -04:00
|
|
|
'Sign in to Deck Hearth'
|
2025-07-24 17:36:10 -04:00
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-07-23 22:26:54 -04:00
|
|
|
|
2025-07-25 11:47:09 -04:00
|
|
|
{/* Quick Login for Testing */}
|
2025-07-28 10:51:39 -04:00
|
|
|
<div className="mt-6 pt-6 border-t border-opacity-20" style={{ borderColor: 'var(--border)' }}>
|
2025-07-24 17:36:10 -04:00
|
|
|
<div className="text-center">
|
|
|
|
|
<p className="text-sm mb-3" style={{ color: 'var(--text-secondary)' }}>
|
2025-07-25 11:47:09 -04:00
|
|
|
Quick Login for Testing:
|
2025-07-24 17:36:10 -04:00
|
|
|
</p>
|
2025-07-28 12:09:58 -04:00
|
|
|
<div className="grid grid-cols-2 gap-3">
|
2025-07-25 11:47:09 -04:00
|
|
|
<button
|
|
|
|
|
type="button"
|
feat(brand): unify on Deck Hearth across in-repo strings + infra (P1 brand decision)
Resolves the launch-blocking 'TCG Vault vs Deck Hearth' inconsistency called out in AGENTS.md line 5 since project setup. Operator gate-0 decision: Deck Hearth wins. Two briefs applied serially. B1 (mechanical): 7-file display + comment sweep. B2 (infrastructure): Redis prefix rename in lib/rate-limit.js (5 prefixes, accept one-time counter reset), package.json + lockfile regen (STOP-on-churn confirmed only name lines changed), admin/alice/bob email rename in seed scripts + login pre-fill + NEW idempotent migration script scripts/migrations/2026-05-24-rename-admin-email.js. Risk 4 PRESERVE applied: test/lib/permission-middleware.test.js retains admin@tcgvault.com literal with 7-line architect-authored why comment (documents pre-fix-auth-bypass bug shape; preserves historical truth per project's gotcha-documentation convention). All 5 D-decisions ratified at gate-1 (Deck Hearth / deck-hearth / deckhearth / admin@deckhearth.com / full deckhearth Redis prefix). Local: lint 128 baseline (B1 + B2), vitest 21/21 (B1 + B2). CI all green: Playwright smoke 3/3 against rebranded preview in 1m4s, forbidden-cors-headers pass, forbidden-endpoints pass, Screenshot diff pass, Vercel deployment complete. Cross-validation lineage: 4th convoy where the same 3-test smoke spec defends auth surface through sweeping change (after PR #15 Layout default-user, PR #19 CORS, PR #20 rate-limit, now this PR #21 brand rename). OPERATOR POST-MERGE ACTION REQUIRED: run 'node scripts/migrations/2026-05-24-rename-admin-email.js' against prod Neon DB before next admin login (ordering: migration FIRST, then any subsequent setup-db invocation). Migration is ESM, idempotent, UNIQUE-collision-safe. PR #21 architect-commit 50ce9ab, B1 ac8c998, B2 1c18d21.
2026-05-25 03:28:29 -04:00
|
|
|
onClick={() => handleQuickLogin('alice@deckhearth.com', 'alice123')}
|
2025-07-28 12:09:58 -04:00
|
|
|
className="px-4 py-2 rounded-lg text-sm font-medium border border-opacity-20 transition-all duration-200 hover:shadow-md backdrop-blur-sm hover:bg-opacity-80"
|
2025-07-25 11:47:09 -04:00
|
|
|
style={{
|
2025-07-28 10:51:39 -04:00
|
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.6)',
|
2025-07-25 11:47:09 -04:00
|
|
|
borderColor: 'var(--border)',
|
|
|
|
|
color: 'var(--text-primary)'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
👤 Alice
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
feat(brand): unify on Deck Hearth across in-repo strings + infra (P1 brand decision)
Resolves the launch-blocking 'TCG Vault vs Deck Hearth' inconsistency called out in AGENTS.md line 5 since project setup. Operator gate-0 decision: Deck Hearth wins. Two briefs applied serially. B1 (mechanical): 7-file display + comment sweep. B2 (infrastructure): Redis prefix rename in lib/rate-limit.js (5 prefixes, accept one-time counter reset), package.json + lockfile regen (STOP-on-churn confirmed only name lines changed), admin/alice/bob email rename in seed scripts + login pre-fill + NEW idempotent migration script scripts/migrations/2026-05-24-rename-admin-email.js. Risk 4 PRESERVE applied: test/lib/permission-middleware.test.js retains admin@tcgvault.com literal with 7-line architect-authored why comment (documents pre-fix-auth-bypass bug shape; preserves historical truth per project's gotcha-documentation convention). All 5 D-decisions ratified at gate-1 (Deck Hearth / deck-hearth / deckhearth / admin@deckhearth.com / full deckhearth Redis prefix). Local: lint 128 baseline (B1 + B2), vitest 21/21 (B1 + B2). CI all green: Playwright smoke 3/3 against rebranded preview in 1m4s, forbidden-cors-headers pass, forbidden-endpoints pass, Screenshot diff pass, Vercel deployment complete. Cross-validation lineage: 4th convoy where the same 3-test smoke spec defends auth surface through sweeping change (after PR #15 Layout default-user, PR #19 CORS, PR #20 rate-limit, now this PR #21 brand rename). OPERATOR POST-MERGE ACTION REQUIRED: run 'node scripts/migrations/2026-05-24-rename-admin-email.js' against prod Neon DB before next admin login (ordering: migration FIRST, then any subsequent setup-db invocation). Migration is ESM, idempotent, UNIQUE-collision-safe. PR #21 architect-commit 50ce9ab, B1 ac8c998, B2 1c18d21.
2026-05-25 03:28:29 -04:00
|
|
|
onClick={() => handleQuickLogin('bob@deckhearth.com', 'bob123')}
|
2025-07-28 12:09:58 -04:00
|
|
|
className="px-4 py-2 rounded-lg text-sm font-medium border border-opacity-20 transition-all duration-200 hover:shadow-md backdrop-blur-sm hover:bg-opacity-80"
|
2025-07-25 11:47:09 -04:00
|
|
|
style={{
|
2025-07-28 10:51:39 -04:00
|
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.6)',
|
2025-07-25 11:47:09 -04:00
|
|
|
borderColor: 'var(--border)',
|
|
|
|
|
color: 'var(--text-primary)'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
👤 Bob
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-07-23 22:26:54 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-07-24 17:36:10 -04:00
|
|
|
|
2025-07-28 12:09:58 -04:00
|
|
|
<div className="text-center">
|
|
|
|
|
<p className="text-sm" style={{ color: 'var(--text-secondary)' }}>
|
|
|
|
|
Don't have an account?{' '}
|
|
|
|
|
<Link href="/signup" className="font-medium gradient-text-flame hover:underline">
|
|
|
|
|
Sign up here
|
|
|
|
|
</Link>
|
|
|
|
|
</p>
|
2025-07-23 22:26:54 -04:00
|
|
|
</div>
|
2025-07-28 12:09:58 -04:00
|
|
|
</form>
|
2025-07-24 17:36:10 -04:00
|
|
|
</div>
|
2025-07-23 22:26:54 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-07-25 12:28:04 -04:00
|
|
|
</AuthLayout>
|
2025-07-23 22:26:54 -04:00
|
|
|
);
|
|
|
|
|
}
|