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 11:01:03 -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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 11:01:03 -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-28 12:09:58 -04:00
|
|
|
<div className="text-center">
|
|
|
|
|
<p className="text-sm" style={{ color: 'var(--text-secondary)' }}>
|
2026-06-02 02:03:39 -04:00
|
|
|
Don't have an account?{' '}
|
2025-07-28 12:09:58 -04:00
|
|
|
<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
|
|
|
);
|
|
|
|
|
}
|