This commit is contained in:
2025-12-31 19:55:43 +01:00
parent 8260bf7baf
commit 167e82a52b
66 changed files with 5124 additions and 228 deletions

View File

@@ -73,20 +73,14 @@ export default function LoginPage() {
setErrors({});
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: formData.email,
password: formData.password,
}),
const { ServiceFactory } = await import('@/lib/services/ServiceFactory');
const serviceFactory = new ServiceFactory(process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001');
const authService = serviceFactory.createAuthService();
await authService.login({
email: formData.email,
password: formData.password,
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Login failed');
}
// Refresh session in context so header updates immediately
await refreshSession();
@@ -102,8 +96,12 @@ export default function LoginPage() {
const handleDemoLogin = async () => {
setLoading(true);
try {
// Demo: Set cookie to indicate driver mode (works without OAuth)
document.cookie = 'gridpilot_demo_mode=driver; path=/; max-age=86400';
const { ServiceFactory } = await import('@/lib/services/ServiceFactory');
const serviceFactory = new ServiceFactory(process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001');
const authService = serviceFactory.createAuthService();
await authService.demoLogin({ role: 'driver' });
await new Promise(resolve => setTimeout(resolve, 500));
router.push(returnTo);
} catch (error) {
@@ -299,7 +297,7 @@ export default function LoginPage() {
className="w-full flex items-center justify-center gap-3 px-4 py-3 rounded-lg bg-gradient-to-r from-deep-graphite to-iron-gray border border-charcoal-outline text-gray-300 hover:border-primary-blue/30 transition-all disabled:opacity-50 group"
>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login (iRacing)</span>
<span>Demo Login</span>
<ChevronRight className="w-4 h-4 text-gray-500 group-hover:translate-x-0.5 transition-transform" />
</motion.button>
@@ -315,6 +313,16 @@ export default function LoginPage() {
</p>
</Card>
{/* Name Immutability Notice */}
<div className="mt-6 p-4 rounded-lg bg-iron-gray/30 border border-charcoal-outline">
<div className="flex items-start gap-3">
<AlertCircle className="w-5 h-5 text-gray-400 flex-shrink-0 mt-0.5" />
<div className="text-xs text-gray-400">
<strong>Note:</strong> Your display name cannot be changed after signup. Please ensure it's correct when creating your account.
</div>
</div>
</div>
{/* Footer */}
<p className="mt-6 text-center text-xs text-gray-500">
By signing in, you agree to our{' '}