Closes the pick-a-name convoy. Applies D1-D5 + Risk 4 PRESERVE per
operator gate-1 ratification.
Infrastructure renames:
- lib/rate-limit.js: 5 Redis key prefixes tcgvault:* → deckhearth:* (D5).
One-time per-15-min / per-1-hour counter reset accepted; no user impact
because counter windows are short anyway. Existing rate-limit state in
Upstash will accumulate at the new prefix on first request.
- package.json: name field tcg-vault → deck-hearth (D2)
- package-lock.json: regenerated for the name change; STOP-on-churn
protocol confirmed only the two name lines changed (no dep churn)
- All three test users (admin/alice/bob) renamed to @deckhearth.com (D4)
- One-off migration script scripts/migrations/2026-05-24-rename-admin-
email.js (NEW): ESM, idempotent, UNIQUE-collision-safe. Per the
no-go-zones rule for new migrations. Operator MUST run post-deploy.
- README.md + TESTING_GUIDE.md operator-caveat blockquotes flagged
- pages/login.js demo-credential pre-fill updated
PRESERVED per Risk 4:
- test/lib/permission-middleware.test.js literal admin@tcgvault.com
with 7-line architect-authored "why" comment block. This is the
documented pre-fix-auth-bypass bug shape; the regression-lock
literal stays as historical truth.
Verification:
- npm run lint: 128 problems (baseline preserved)
- npm run test:run: 21/21 pass (preserved literal keeps green)
- Grep across full repo: 0 hits for TCG Vault / tcgvault / tcg-vault
except the explicit preserve in the test file + .convoys/ historical
- lib/rate-limit.js: 5 deckhearth: prefixes, 0 tcgvault: prefixes
- node --check on the new migration script: exit 0
- git diff package-lock.json: only the 2 "name": lines changed (no churn)
Operator post-merge action:
- Run `node scripts/migrations/2026-05-24-rename-admin-email.js` against
the production Neon DB. Order matters: migration FIRST, then any
subsequent `npm run setup-db` invocation. Migration script will refuse
to run if collision detected (means setup-db already ran post-rename).
Architect brief: .convoys/pick-a-name/brief-2-infrastructure-and-email-migration.md
Architect commit: 50ce9ab
Operator gate-1: D1-D5 + Risk 4 PRESERVE ratified.
Co-authored-by: Cursor <cursoragent@cursor.com>
212 lines
No EOL
7.9 KiB
JavaScript
212 lines
No EOL
7.9 KiB
JavaScript
import { useState } from 'react';
|
|
import { useRouter } from 'next/router';
|
|
import Link from 'next/link';
|
|
import AuthLayout from '../components/AuthLayout';
|
|
import AnimatedFireLogo from '../components/AnimatedFireLogo';
|
|
|
|
export default function Login() {
|
|
const router = useRouter();
|
|
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('');
|
|
};
|
|
|
|
const handleSubmit = async (e) => {
|
|
e.preventDefault();
|
|
setLoading(true);
|
|
setError('');
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(formData)
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
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');
|
|
}
|
|
} else {
|
|
setError(data.error || 'Login failed');
|
|
}
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
setError('Network error. Please try again.');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
const handleQuickLogin = (email, password) => {
|
|
setFormData({ email, password });
|
|
};
|
|
|
|
return (
|
|
<AuthLayout>
|
|
<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">
|
|
<div className="mb-6 flex justify-center">
|
|
<AnimatedFireLogo size={100} />
|
|
</div>
|
|
<h2 className="text-3xl font-bold gradient-text-flame mb-2">
|
|
Welcome to Deck Hearth
|
|
</h2>
|
|
<p className="mt-2 text-sm" style={{ color: 'var(--text-secondary)' }}>
|
|
Sign in to access your trading card collection
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<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)'
|
|
}}
|
|
>
|
|
<form onSubmit={handleSubmit} className="space-y-6">
|
|
{error && (
|
|
<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>
|
|
</div>
|
|
)}
|
|
|
|
<div>
|
|
<label htmlFor="email" className="block text-sm font-medium mb-2" style={{ color: 'var(--text-primary)' }}>
|
|
Email Address
|
|
</label>
|
|
<input
|
|
id="email"
|
|
name="email"
|
|
type="email"
|
|
autoComplete="email"
|
|
required
|
|
value={formData.email}
|
|
onChange={(e) => handleInputChange('email', e.target.value)}
|
|
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"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-primary)'
|
|
}}
|
|
placeholder="Enter your email"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor="password" className="block text-sm font-medium mb-2" style={{ color: 'var(--text-primary)' }}>
|
|
Password
|
|
</label>
|
|
<input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
value={formData.password}
|
|
onChange={(e) => handleInputChange('password', e.target.value)}
|
|
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"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-primary)'
|
|
}}
|
|
placeholder="Enter your password"
|
|
/>
|
|
</div>
|
|
|
|
<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'
|
|
: 'gradient-bg-ember text-white hover:shadow-xl transform hover:scale-105 hover:shadow-orange-500/20'
|
|
}`}
|
|
>
|
|
{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>
|
|
) : (
|
|
'Sign in to Deck Hearth'
|
|
)}
|
|
</button>
|
|
</div>
|
|
|
|
{/* Quick Login for Testing */}
|
|
<div className="mt-6 pt-6 border-t border-opacity-20" style={{ borderColor: 'var(--border)' }}>
|
|
<div className="text-center">
|
|
<p className="text-sm mb-3" style={{ color: 'var(--text-secondary)' }}>
|
|
Quick Login for Testing:
|
|
</p>
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<button
|
|
type="button"
|
|
onClick={() => handleQuickLogin('alice@deckhearth.com', 'alice123')}
|
|
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"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.6)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-primary)'
|
|
}}
|
|
>
|
|
👤 Alice
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => handleQuickLogin('bob@deckhearth.com', 'bob123')}
|
|
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"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.6)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-primary)'
|
|
}}
|
|
>
|
|
👤 Bob
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</AuthLayout>
|
|
);
|
|
}
|