auth rework

This commit is contained in:
2025-12-17 15:34:56 +01:00
parent a213a5cf9f
commit 75eaa1aa9f
24 changed files with 6115 additions and 1992 deletions

View File

@@ -1,29 +1,273 @@
import Link from 'next/link';
'use client';
interface IracingAuthPageProps {
searchParams: Promise<{
returnTo?: string;
}>;
import { useState, useEffect } from 'react';
import Link from 'next/link';
import { useSearchParams } from 'next/navigation';
import { motion, AnimatePresence, useReducedMotion } from 'framer-motion';
import {
Gamepad2,
Flag,
ArrowRight,
Shield,
Link as LinkIcon,
User,
Trophy,
BarChart3,
CheckCircle2,
Loader2,
} from 'lucide-react';
import Card from '@/components/ui/Card';
import Button from '@/components/ui/Button';
import Heading from '@/components/ui/Heading';
interface ConnectionStep {
id: number;
icon: typeof Gamepad2;
title: string;
description: string;
}
export default async function IracingAuthPage({ searchParams }: IracingAuthPageProps) {
const params = await searchParams;
const returnTo = params.returnTo ?? '/dashboard';
const CONNECTION_STEPS: ConnectionStep[] = [
{
id: 1,
icon: Gamepad2,
title: 'Connect iRacing',
description: 'Authorize GridPilot to access your profile',
},
{
id: 2,
icon: User,
title: 'Import Profile',
description: 'We fetch your racing stats and history',
},
{
id: 3,
icon: Trophy,
title: 'Sync Achievements',
description: 'Your licenses, iRating, and results',
},
{
id: 4,
icon: BarChart3,
title: 'Ready to Race',
description: 'Access full GridPilot features',
},
];
const BENEFITS = [
'Automatic profile creation with your iRacing data',
'Real-time stats sync including iRating and Safety Rating',
'Import your racing history and achievements',
'No manual data entry required',
'Verified driver identity in leagues',
];
export default function IracingAuthPage() {
const searchParams = useSearchParams();
const returnTo = searchParams.get('returnTo') ?? '/dashboard';
const startUrl = `/auth/iracing/start?returnTo=${encodeURIComponent(returnTo)}`;
const shouldReduceMotion = useReducedMotion();
const [isMounted, setIsMounted] = useState(false);
const [activeStep, setActiveStep] = useState(0);
const [isHovering, setIsHovering] = useState(false);
useEffect(() => {
setIsMounted(true);
}, []);
useEffect(() => {
if (!isMounted || isHovering) return;
const interval = setInterval(() => {
setActiveStep((prev) => (prev + 1) % CONNECTION_STEPS.length);
}, 2500);
return () => clearInterval(interval);
}, [isMounted, isHovering]);
return (
<main className="min-h-screen flex items-center justify-center bg-deep-graphite">
<div className="max-w-md w-full px-6 py-8 bg-iron-gray/80 rounded-lg border border-white/10 shadow-xl">
<h1 className="text-2xl font-semibold text-white mb-4">Authenticate with iRacing</h1>
<p className="text-sm text-gray-300 mb-6">
Connect a demo iRacing identity to explore the GridPilot dashboard with seeded data.
<main className="min-h-screen bg-deep-graphite flex items-center justify-center px-4 py-12">
{/* Background Pattern */}
<div className="absolute inset-0 bg-gradient-to-br from-primary-blue/5 via-transparent to-purple-600/5" />
<div className="absolute inset-0 opacity-5">
<div className="absolute inset-0" style={{
backgroundImage: `url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")`,
}} />
</div>
<div className="relative w-full max-w-2xl">
{/* Header */}
<div className="text-center mb-8">
<div className="flex justify-center gap-4 mb-6">
<motion.div
initial={{ scale: 0.8, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
transition={{ delay: 0.1 }}
className="flex h-14 w-14 items-center justify-center rounded-xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30"
>
<Flag className="w-7 h-7 text-primary-blue" />
</motion.div>
<motion.div
initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
transition={{ delay: 0.2 }}
className="flex items-center"
>
<LinkIcon className="w-6 h-6 text-gray-500" />
</motion.div>
<motion.div
initial={{ scale: 0.8, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
transition={{ delay: 0.3 }}
className="flex h-14 w-14 items-center justify-center rounded-xl bg-gradient-to-br from-orange-500/20 to-red-600/10 border border-orange-500/30"
>
<Gamepad2 className="w-7 h-7 text-orange-400" />
</motion.div>
</div>
<Heading level={1} className="mb-3">Connect Your iRacing Account</Heading>
<p className="text-gray-400 text-lg max-w-md mx-auto">
Link your iRacing profile for automatic stats sync and verified driver identity.
</p>
</div>
<Card className="relative overflow-hidden">
{/* Background accent */}
<div className="absolute top-0 right-0 w-48 h-48 bg-gradient-to-bl from-primary-blue/5 to-transparent rounded-bl-full" />
<div className="absolute bottom-0 left-0 w-32 h-32 bg-gradient-to-tr from-orange-500/5 to-transparent rounded-tr-full" />
<div className="relative">
{/* Connection Flow Animation */}
<div
className="bg-iron-gray/50 rounded-xl border border-charcoal-outline p-6 mb-6"
onMouseEnter={() => setIsHovering(true)}
onMouseLeave={() => setIsHovering(false)}
>
<p className="text-xs text-gray-500 text-center mb-4">Connection Flow</p>
{/* Steps */}
<div className="flex justify-between items-start gap-2">
{CONNECTION_STEPS.map((step, index) => {
const isActive = index === activeStep;
const isCompleted = index < activeStep;
const StepIcon = step.icon;
return (
<motion.button
key={step.id}
onClick={() => setActiveStep(index)}
className="flex flex-col items-center text-center flex-1 cursor-pointer"
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
>
<motion.div
className={`w-12 h-12 rounded-xl border flex items-center justify-center mb-2 transition-all duration-300 ${
isActive
? 'bg-primary-blue/20 border-primary-blue shadow-[0_0_15px_rgba(25,140,255,0.3)]'
: isCompleted
? 'bg-performance-green/20 border-performance-green/50'
: 'bg-deep-graphite border-charcoal-outline'
}`}
animate={isActive && !shouldReduceMotion ? {
scale: [1, 1.08, 1],
transition: { duration: 1, repeat: Infinity }
} : {}}
>
{isCompleted ? (
<CheckCircle2 className="w-5 h-5 text-performance-green" />
) : (
<StepIcon className={`w-5 h-5 ${isActive ? 'text-primary-blue' : 'text-gray-500'}`} />
)}
</motion.div>
<h4 className={`text-xs font-medium transition-colors ${
isActive ? 'text-white' : 'text-gray-500'
}`}>
{step.title}
</h4>
</motion.button>
);
})}
</div>
{/* Active Step Description */}
<AnimatePresence mode="wait">
<motion.div
key={activeStep}
initial={{ opacity: 0, y: 5 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -5 }}
transition={{ duration: 0.2 }}
className="mt-4 text-center"
>
<p className="text-sm text-gray-400">
{CONNECTION_STEPS[activeStep].description}
</p>
</motion.div>
</AnimatePresence>
</div>
{/* Benefits List */}
<div className="mb-6">
<h3 className="text-sm font-medium text-gray-300 mb-3">What you'll get:</h3>
<ul className="space-y-2">
{BENEFITS.map((benefit, index) => (
<motion.li
key={index}
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: 0.4 + index * 0.05 }}
className="flex items-start gap-2 text-sm text-gray-400"
>
<CheckCircle2 className="w-4 h-4 text-performance-green flex-shrink-0 mt-0.5" />
{benefit}
</motion.li>
))}
</ul>
</div>
{/* Connect Button */}
<Link href={startUrl} className="block">
<Button
variant="primary"
className="w-full flex items-center justify-center gap-3 py-4"
>
<Gamepad2 className="w-5 h-5" />
<span>Connect iRacing Account</span>
<ArrowRight className="w-4 h-4" />
</Button>
</Link>
{/* Trust Indicators */}
<div className="mt-6 pt-6 border-t border-charcoal-outline">
<div className="flex items-center justify-center gap-6 text-xs text-gray-500">
<div className="flex items-center gap-2">
<Shield className="w-4 h-4" />
<span>Secure OAuth connection</span>
</div>
<div className="flex items-center gap-2">
<LinkIcon className="w-4 h-4" />
<span>Read-only access</span>
</div>
</div>
</div>
{/* Alternative */}
<p className="mt-6 text-center text-sm text-gray-500">
Don't have iRacing?{' '}
<Link href="/auth/signup" className="text-primary-blue hover:underline">
Create account with email
</Link>
</p>
</div>
</Card>
{/* Footer */}
<p className="mt-6 text-center text-xs text-gray-500">
GridPilot only requests read access to your iRacing profile.
<br />
We never access your payment info or modify your account.
</p>
<Link
href={startUrl}
className="inline-flex items-center justify-center px-4 py-2 rounded-md bg-primary-blue text-sm font-medium text-white hover:bg-primary-blue/90 transition-colors w-full"
>
Start iRacing demo login
</Link>
</div>
</main>
);

View File

@@ -3,6 +3,7 @@
import { useState, FormEvent, type ChangeEvent } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import Link from 'next/link';
import { motion, AnimatePresence } from 'framer-motion';
import {
Mail,
Lock,
@@ -13,6 +14,11 @@ import {
Flag,
ArrowRight,
Gamepad2,
Car,
Users,
Trophy,
Shield,
ChevronRight,
} from 'lucide-react';
import Card from '@/components/ui/Card';
@@ -20,6 +26,7 @@ import Button from '@/components/ui/Button';
import Input from '@/components/ui/Input';
import Heading from '@/components/ui/Heading';
import { useAuth } from '@/lib/auth/AuthContext';
import AuthWorkflowMockup from '@/components/auth/AuthWorkflowMockup';
interface FormErrors {
email?: string;
@@ -27,6 +34,27 @@ interface FormErrors {
submit?: string;
}
const USER_ROLES = [
{
icon: Car,
title: 'Driver',
description: 'Race, track stats, join teams',
color: 'primary-blue',
},
{
icon: Trophy,
title: 'League Admin',
description: 'Organize leagues and events',
color: 'performance-green',
},
{
icon: Users,
title: 'Team Manager',
description: 'Manage team and drivers',
color: 'purple-400',
},
];
export default function LoginPage() {
const router = useRouter();
const searchParams = useSearchParams();
@@ -97,8 +125,10 @@ export default function LoginPage() {
const handleDemoLogin = async () => {
setLoading(true);
try {
// Redirect to iRacing auth start route
router.push(`/auth/iracing/start?returnTo=${encodeURIComponent(returnTo)}`);
// Demo: Set cookie to indicate driver mode (works without OAuth)
document.cookie = 'gridpilot_demo_mode=driver; path=/; max-age=86400';
await new Promise(resolve => setTimeout(resolve, 500));
router.push(returnTo);
} catch (error) {
setErrors({
submit: 'Demo login failed. Please try again.',
@@ -108,7 +138,7 @@ export default function LoginPage() {
};
return (
<main className="min-h-screen bg-deep-graphite flex items-center justify-center px-4 py-12">
<main className="min-h-screen bg-deep-graphite flex">
{/* Background Pattern */}
<div className="absolute inset-0 bg-gradient-to-br from-primary-blue/5 via-transparent to-purple-600/5" />
<div className="absolute inset-0 opacity-5">
@@ -117,148 +147,238 @@ export default function LoginPage() {
}} />
</div>
<div className="relative w-full max-w-md">
{/* Logo/Header */}
<div className="text-center mb-8">
<div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30 mx-auto mb-4">
<Flag className="w-8 h-8 text-primary-blue" />
{/* Left Side - Info Panel (Hidden on mobile) */}
<div className="hidden lg:flex lg:w-1/2 relative items-center justify-center p-12">
<div className="max-w-lg">
{/* Logo */}
<div className="flex items-center gap-3 mb-8">
<div className="flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30">
<Flag className="w-6 h-6 text-primary-blue" />
</div>
<span className="text-2xl font-bold text-white">GridPilot</span>
</div>
<Heading level={1} className="mb-2">Welcome Back</Heading>
<p className="text-gray-400">
Sign in to continue to GridPilot
<Heading level={2} className="text-white mb-4">
Your Sim Racing Infrastructure
</Heading>
<p className="text-gray-400 text-lg mb-8">
Manage leagues, track performance, join teams, and compete with drivers worldwide. One account, multiple roles.
</p>
{/* Role Cards */}
<div className="space-y-3 mb-8">
{USER_ROLES.map((role, index) => (
<motion.div
key={role.title}
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: index * 0.1 }}
className="flex items-center gap-4 p-4 rounded-xl bg-iron-gray/50 border border-charcoal-outline"
>
<div className={`w-10 h-10 rounded-lg bg-${role.color}/20 flex items-center justify-center`}>
<role.icon className={`w-5 h-5 text-${role.color}`} />
</div>
<div>
<h4 className="text-white font-medium">{role.title}</h4>
<p className="text-sm text-gray-500">{role.description}</p>
</div>
</motion.div>
))}
</div>
{/* Workflow Mockup */}
<AuthWorkflowMockup />
{/* Trust Indicators */}
<div className="mt-8 flex items-center gap-6 text-sm text-gray-500">
<div className="flex items-center gap-2">
<Shield className="w-4 h-4" />
<span>Secure login</span>
</div>
<div className="flex items-center gap-2">
<Gamepad2 className="w-4 h-4" />
<span>iRacing verified</span>
</div>
</div>
</div>
</div>
<Card className="relative overflow-hidden">
{/* Background accent */}
<div className="absolute top-0 right-0 w-32 h-32 bg-gradient-to-bl from-primary-blue/10 to-transparent rounded-bl-full" />
<form onSubmit={handleSubmit} className="relative space-y-5">
{/* Email */}
<div>
<label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-2">
Email Address
</label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="email"
type="email"
value={formData.email}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, email: e.target.value })}
error={!!errors.email}
errorMessage={errors.email}
placeholder="you@example.com"
disabled={loading}
className="pl-10"
autoComplete="email"
/>
</div>
</div>
{/* Password */}
<div>
<div className="flex items-center justify-between mb-2">
<label htmlFor="password" className="block text-sm font-medium text-gray-300">
Password
</label>
<Link href="/auth/forgot-password" className="text-xs text-primary-blue hover:underline">
Forgot password?
</Link>
</div>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={formData.password}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, password: e.target.value })}
error={!!errors.password}
errorMessage={errors.password}
placeholder="••••••••"
disabled={loading}
className="pl-10 pr-10"
autoComplete="current-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300"
>
{showPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</button>
</div>
</div>
{/* Error Message */}
{errors.submit && (
<div className="flex items-start gap-3 p-3 rounded-lg bg-red-500/10 border border-red-500/30">
<AlertCircle className="w-5 h-5 text-red-400 flex-shrink-0 mt-0.5" />
<p className="text-sm text-red-400">{errors.submit}</p>
</div>
)}
{/* Submit Button */}
<Button
type="submit"
variant="primary"
disabled={loading}
className="w-full flex items-center justify-center gap-2"
>
{loading ? (
<>
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
Signing in...
</>
) : (
<>
<LogIn className="w-4 h-4" />
Sign In
</>
)}
</Button>
</form>
{/* Divider */}
<div className="relative my-6">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-charcoal-outline" />
</div>
<div className="relative flex justify-center text-xs">
<span className="px-4 bg-iron-gray text-gray-500">or continue with</span>
{/* Right Side - Login Form */}
<div className="flex-1 flex items-center justify-center px-4 py-12">
<div className="relative w-full max-w-md">
{/* Mobile Logo/Header */}
<div className="text-center mb-8 lg:hidden">
<div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30 mx-auto mb-4">
<Flag className="w-8 h-8 text-primary-blue" />
</div>
<Heading level={1} className="mb-2">Welcome Back</Heading>
<p className="text-gray-400">
Sign in to continue to GridPilot
</p>
</div>
{/* Demo Login */}
<button
type="button"
onClick={handleDemoLogin}
disabled={loading}
className="w-full flex items-center justify-center gap-3 px-4 py-3 rounded-lg bg-deep-graphite border border-charcoal-outline text-gray-300 hover:bg-iron-gray hover:border-primary-blue/30 transition-all disabled:opacity-50"
>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login (iRacing)</span>
</button>
{/* Desktop Header */}
<div className="hidden lg:block text-center mb-8">
<Heading level={2} className="mb-2">Welcome Back</Heading>
<p className="text-gray-400">
Sign in to access your racing dashboard
</p>
</div>
{/* Sign Up Link */}
<p className="mt-6 text-center text-sm text-gray-400">
Don't have an account?{' '}
<Link
href={`/auth/signup${returnTo !== '/dashboard' ? `?returnTo=${encodeURIComponent(returnTo)}` : ''}`}
className="text-primary-blue hover:underline font-medium"
<Card className="relative overflow-hidden">
{/* Background accent */}
<div className="absolute top-0 right-0 w-32 h-32 bg-gradient-to-bl from-primary-blue/10 to-transparent rounded-bl-full" />
<form onSubmit={handleSubmit} className="relative space-y-5">
{/* Email */}
<div>
<label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-2">
Email Address
</label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="email"
type="email"
value={formData.email}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, email: e.target.value })}
error={!!errors.email}
errorMessage={errors.email}
placeholder="you@example.com"
disabled={loading}
className="pl-10"
autoComplete="email"
/>
</div>
</div>
{/* Password */}
<div>
<div className="flex items-center justify-between mb-2">
<label htmlFor="password" className="block text-sm font-medium text-gray-300">
Password
</label>
<Link href="/auth/forgot-password" className="text-xs text-primary-blue hover:underline">
Forgot password?
</Link>
</div>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={formData.password}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, password: e.target.value })}
error={!!errors.password}
errorMessage={errors.password}
placeholder="••••••••"
disabled={loading}
className="pl-10 pr-10"
autoComplete="current-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300"
>
{showPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</button>
</div>
</div>
{/* Error Message */}
{errors.submit && (
<motion.div
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
className="flex items-start gap-3 p-3 rounded-lg bg-red-500/10 border border-red-500/30"
>
<AlertCircle className="w-5 h-5 text-red-400 flex-shrink-0 mt-0.5" />
<p className="text-sm text-red-400">{errors.submit}</p>
</motion.div>
)}
{/* Submit Button */}
<Button
type="submit"
variant="primary"
disabled={loading}
className="w-full flex items-center justify-center gap-2"
>
{loading ? (
<>
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
Signing in...
</>
) : (
<>
<LogIn className="w-4 h-4" />
Sign In
</>
)}
</Button>
</form>
{/* Divider */}
<div className="relative my-6">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-charcoal-outline" />
</div>
<div className="relative flex justify-center text-xs">
<span className="px-4 bg-iron-gray text-gray-500">or continue with</span>
</div>
</div>
{/* Demo Login */}
<motion.button
type="button"
onClick={handleDemoLogin}
disabled={loading}
whileHover={{ scale: 1.01 }}
whileTap={{ scale: 0.99 }}
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"
>
Create one
</Link>
</p>
</Card>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login (iRacing)</span>
<ChevronRight className="w-4 h-4 text-gray-500 group-hover:translate-x-0.5 transition-transform" />
</motion.button>
{/* Footer */}
<p className="mt-6 text-center text-xs text-gray-500">
By signing in, you agree to our{' '}
<Link href="/terms" className="text-gray-400 hover:underline">Terms of Service</Link>
{' '}and{' '}
<Link href="/privacy" className="text-gray-400 hover:underline">Privacy Policy</Link>
</p>
{/* Sign Up Link */}
<p className="mt-6 text-center text-sm text-gray-400">
Don't have an account?{' '}
<Link
href={`/auth/signup${returnTo !== '/dashboard' ? `?returnTo=${encodeURIComponent(returnTo)}` : ''}`}
className="text-primary-blue hover:underline font-medium"
>
Create one
</Link>
</p>
</Card>
{/* Footer */}
<p className="mt-6 text-center text-xs text-gray-500">
By signing in, you agree to our{' '}
<Link href="/terms" className="text-gray-400 hover:underline">Terms of Service</Link>
{' '}and{' '}
<Link href="/privacy" className="text-gray-400 hover:underline">Privacy Policy</Link>
</p>
{/* Mobile Role Info */}
<div className="mt-8 lg:hidden">
<p className="text-center text-xs text-gray-500 mb-4">One account for all roles</p>
<div className="flex justify-center gap-6">
{USER_ROLES.map((role) => (
<div key={role.title} className="flex flex-col items-center">
<div className={`w-8 h-8 rounded-lg bg-${role.color}/20 flex items-center justify-center mb-1`}>
<role.icon className={`w-4 h-4 text-${role.color}`} />
</div>
<span className="text-xs text-gray-500">{role.title}</span>
</div>
))}
</div>
</div>
</div>
</div>
</main>
);

View File

@@ -3,6 +3,7 @@
import { useState, useEffect, FormEvent, type ChangeEvent } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import Link from 'next/link';
import { motion, AnimatePresence } from 'framer-motion';
import {
Mail,
Lock,
@@ -16,6 +17,13 @@ import {
X,
Gamepad2,
Loader2,
Car,
Users,
Trophy,
Shield,
ChevronRight,
ArrowRight,
Sparkles,
} from 'lucide-react';
import Card from '@/components/ui/Card';
@@ -23,6 +31,7 @@ import Button from '@/components/ui/Button';
import Input from '@/components/ui/Input';
import Heading from '@/components/ui/Heading';
import { useAuth } from '@/lib/auth/AuthContext';
import AuthWorkflowMockup from '@/components/auth/AuthWorkflowMockup';
interface FormErrors {
displayName?: string;
@@ -52,6 +61,36 @@ function checkPasswordStrength(password: string): PasswordStrength {
return { score, label: 'Strong', color: 'bg-performance-green' };
}
const USER_ROLES = [
{
icon: Car,
title: 'Driver',
description: 'Race, track stats, join teams',
color: 'primary-blue',
},
{
icon: Trophy,
title: 'League Admin',
description: 'Organize leagues and events',
color: 'performance-green',
},
{
icon: Users,
title: 'Team Manager',
description: 'Manage team and drivers',
color: 'purple-400',
},
];
const FEATURES = [
'Track your racing statistics and progress',
'Join or create competitive leagues',
'Build or join racing teams',
'Connect your iRacing account',
'Compete in organized events',
'Access detailed performance analytics',
];
export default function SignupPage() {
const router = useRouter();
const searchParams = useSearchParams();
@@ -169,8 +208,10 @@ export default function SignupPage() {
const handleDemoLogin = async () => {
setLoading(true);
try {
// Redirect to iRacing auth start route
router.push(`/auth/iracing/start?returnTo=${encodeURIComponent(returnTo)}`);
// Demo: Set cookie to indicate driver mode (works without OAuth)
document.cookie = 'gridpilot_demo_mode=driver; path=/; max-age=86400';
await new Promise(resolve => setTimeout(resolve, 500));
router.push(returnTo === '/onboarding' ? '/dashboard' : returnTo);
} catch {
setErrors({
submit: 'Demo login failed. Please try again.',
@@ -189,7 +230,7 @@ export default function SignupPage() {
}
return (
<main className="min-h-screen bg-deep-graphite flex items-center justify-center px-4 py-12">
<main className="min-h-screen bg-deep-graphite flex">
{/* Background Pattern */}
<div className="absolute inset-0 bg-gradient-to-br from-primary-blue/5 via-transparent to-purple-600/5" />
<div className="absolute inset-0 opacity-5">
@@ -198,236 +239,350 @@ export default function SignupPage() {
}} />
</div>
<div className="relative w-full max-w-md">
{/* Logo/Header */}
<div className="text-center mb-8">
<div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30 mx-auto mb-4">
<Flag className="w-8 h-8 text-primary-blue" />
{/* Left Side - Info Panel (Hidden on mobile) */}
<div className="hidden lg:flex lg:w-1/2 relative items-center justify-center p-12">
<div className="max-w-lg">
{/* Logo */}
<div className="flex items-center gap-3 mb-8">
<div className="flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30">
<Flag className="w-6 h-6 text-primary-blue" />
</div>
<span className="text-2xl font-bold text-white">GridPilot</span>
</div>
<Heading level={1} className="mb-2">Join GridPilot</Heading>
<p className="text-gray-400">
Create your account and start racing
<Heading level={2} className="text-white mb-4">
Start Your Racing Journey
</Heading>
<p className="text-gray-400 text-lg mb-8">
Join thousands of sim racers. One account gives you access to all roles - race as a driver, organize leagues, or manage teams.
</p>
</div>
<Card className="relative overflow-hidden">
{/* Background accent */}
<div className="absolute top-0 right-0 w-32 h-32 bg-gradient-to-bl from-primary-blue/10 to-transparent rounded-bl-full" />
<form onSubmit={handleSubmit} className="relative space-y-5">
{/* Display Name */}
<div>
<label htmlFor="displayName" className="block text-sm font-medium text-gray-300 mb-2">
Display Name
</label>
<div className="relative">
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="displayName"
type="text"
value={formData.displayName}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, displayName: e.target.value })}
error={!!errors.displayName}
errorMessage={errors.displayName}
placeholder="SpeedyRacer42"
disabled={loading}
className="pl-10"
autoComplete="username"
/>
</div>
<p className="mt-1 text-xs text-gray-500">This is how other drivers will see you</p>
</div>
{/* Email */}
<div>
<label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-2">
Email Address
</label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="email"
type="email"
value={formData.email}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, email: e.target.value })}
error={!!errors.email}
errorMessage={errors.email}
placeholder="you@example.com"
disabled={loading}
className="pl-10"
autoComplete="email"
/>
</div>
</div>
{/* Password */}
<div>
<label htmlFor="password" className="block text-sm font-medium text-gray-300 mb-2">
Password
</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={formData.password}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, password: e.target.value })}
error={!!errors.password}
errorMessage={errors.password}
placeholder="••••••••"
disabled={loading}
className="pl-10 pr-10"
autoComplete="new-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300"
>
{showPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</button>
</div>
{/* Password Strength */}
{formData.password && (
<div className="mt-3 space-y-2">
<div className="flex items-center gap-2">
<div className="flex-1 h-1.5 rounded-full bg-charcoal-outline overflow-hidden">
<div
className={`h-full transition-all duration-300 ${passwordStrength.color}`}
style={{ width: `${(passwordStrength.score / 5) * 100}%` }}
/>
</div>
<span className={`text-xs font-medium ${
passwordStrength.score <= 1 ? 'text-red-400' :
passwordStrength.score <= 2 ? 'text-warning-amber' :
passwordStrength.score <= 3 ? 'text-primary-blue' :
'text-performance-green'
}`}>
{passwordStrength.label}
</span>
</div>
<div className="grid grid-cols-2 gap-1">
{passwordRequirements.map((req, index) => (
<div key={index} className="flex items-center gap-1.5 text-xs">
{req.met ? (
<Check className="w-3 h-3 text-performance-green" />
) : (
<X className="w-3 h-3 text-gray-500" />
)}
<span className={req.met ? 'text-gray-300' : 'text-gray-500'}>
{req.label}
</span>
</div>
))}
</div>
{/* Role Cards */}
<div className="space-y-3 mb-8">
{USER_ROLES.map((role, index) => (
<motion.div
key={role.title}
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: index * 0.1 }}
className="flex items-center gap-4 p-4 rounded-xl bg-iron-gray/50 border border-charcoal-outline"
>
<div className={`w-10 h-10 rounded-lg bg-${role.color}/20 flex items-center justify-center`}>
<role.icon className={`w-5 h-5 text-${role.color}`} />
</div>
)}
</div>
{/* Confirm Password */}
<div>
<label htmlFor="confirmPassword" className="block text-sm font-medium text-gray-300 mb-2">
Confirm Password
</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="confirmPassword"
type={showConfirmPassword ? 'text' : 'password'}
value={formData.confirmPassword}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, confirmPassword: e.target.value })}
error={!!errors.confirmPassword}
errorMessage={errors.confirmPassword}
placeholder="••••••••"
disabled={loading}
className="pl-10 pr-10"
autoComplete="new-password"
/>
<button
type="button"
onClick={() => setShowConfirmPassword(!showConfirmPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300"
>
{showConfirmPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</button>
</div>
{formData.confirmPassword && formData.password === formData.confirmPassword && (
<p className="mt-1 text-xs text-performance-green flex items-center gap-1">
<Check className="w-3 h-3" /> Passwords match
</p>
)}
</div>
{/* Error Message */}
{errors.submit && (
<div className="flex items-start gap-3 p-3 rounded-lg bg-red-500/10 border border-red-500/30">
<AlertCircle className="w-5 h-5 text-red-400 flex-shrink-0 mt-0.5" />
<p className="text-sm text-red-400">{errors.submit}</p>
</div>
)}
{/* Submit Button */}
<Button
type="submit"
variant="primary"
disabled={loading}
className="w-full flex items-center justify-center gap-2"
>
{loading ? (
<>
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
Creating account...
</>
) : (
<>
<UserPlus className="w-4 h-4" />
Create Account
</>
)}
</Button>
</form>
{/* Divider */}
<div className="relative my-6">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-charcoal-outline" />
</div>
<div className="relative flex justify-center text-xs">
<span className="px-4 bg-iron-gray text-gray-500">or continue with</span>
</div>
<div>
<h4 className="text-white font-medium">{role.title}</h4>
<p className="text-sm text-gray-500">{role.description}</p>
</div>
</motion.div>
))}
</div>
{/* Demo Login */}
<button
type="button"
onClick={handleDemoLogin}
disabled={loading}
className="w-full flex items-center justify-center gap-3 px-4 py-3 rounded-lg bg-deep-graphite border border-charcoal-outline text-gray-300 hover:bg-iron-gray hover:border-primary-blue/30 transition-all disabled:opacity-50"
>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login (iRacing)</span>
</button>
{/* Features List */}
<div className="bg-iron-gray/30 rounded-xl border border-charcoal-outline p-5 mb-8">
<div className="flex items-center gap-2 mb-4">
<Sparkles className="w-4 h-4 text-primary-blue" />
<span className="text-sm font-medium text-white">What you'll get</span>
</div>
<ul className="space-y-2">
{FEATURES.map((feature, index) => (
<motion.li
key={index}
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: 0.3 + index * 0.05 }}
className="flex items-center gap-2 text-sm text-gray-400"
>
<Check className="w-3.5 h-3.5 text-performance-green flex-shrink-0" />
{feature}
</motion.li>
))}
</ul>
</div>
{/* Login Link */}
<p className="mt-6 text-center text-sm text-gray-400">
Already have an account?{' '}
<Link
href={`/auth/login${returnTo !== '/onboarding' ? `?returnTo=${encodeURIComponent(returnTo)}` : ''}`}
className="text-primary-blue hover:underline font-medium"
{/* Trust Indicators */}
<div className="flex items-center gap-6 text-sm text-gray-500">
<div className="flex items-center gap-2">
<Shield className="w-4 h-4" />
<span>Secure signup</span>
</div>
<div className="flex items-center gap-2">
<Gamepad2 className="w-4 h-4" />
<span>iRacing integration</span>
</div>
</div>
</div>
</div>
{/* Right Side - Signup Form */}
<div className="flex-1 flex items-center justify-center px-4 py-12 overflow-y-auto">
<div className="relative w-full max-w-md">
{/* Mobile Logo/Header */}
<div className="text-center mb-8 lg:hidden">
<div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-primary-blue/20 to-purple-600/10 border border-primary-blue/30 mx-auto mb-4">
<Flag className="w-8 h-8 text-primary-blue" />
</div>
<Heading level={1} className="mb-2">Join GridPilot</Heading>
<p className="text-gray-400">
Create your account and start racing
</p>
</div>
{/* Desktop Header */}
<div className="hidden lg:block text-center mb-8">
<Heading level={2} className="mb-2">Create Account</Heading>
<p className="text-gray-400">
Get started with your free account
</p>
</div>
<Card className="relative overflow-hidden">
{/* Background accent */}
<div className="absolute top-0 right-0 w-32 h-32 bg-gradient-to-bl from-primary-blue/10 to-transparent rounded-bl-full" />
<form onSubmit={handleSubmit} className="relative space-y-4">
{/* Display Name */}
<div>
<label htmlFor="displayName" className="block text-sm font-medium text-gray-300 mb-2">
Display Name
</label>
<div className="relative">
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="displayName"
type="text"
value={formData.displayName}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, displayName: e.target.value })}
error={!!errors.displayName}
errorMessage={errors.displayName}
placeholder="SpeedyRacer42"
disabled={loading}
className="pl-10"
autoComplete="username"
/>
</div>
<p className="mt-1 text-xs text-gray-500">This is how other drivers will see you</p>
</div>
{/* Email */}
<div>
<label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-2">
Email Address
</label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="email"
type="email"
value={formData.email}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, email: e.target.value })}
error={!!errors.email}
errorMessage={errors.email}
placeholder="you@example.com"
disabled={loading}
className="pl-10"
autoComplete="email"
/>
</div>
</div>
{/* Password */}
<div>
<label htmlFor="password" className="block text-sm font-medium text-gray-300 mb-2">
Password
</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={formData.password}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, password: e.target.value })}
error={!!errors.password}
errorMessage={errors.password}
placeholder="••••••••"
disabled={loading}
className="pl-10 pr-10"
autoComplete="new-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300"
>
{showPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</button>
</div>
{/* Password Strength */}
{formData.password && (
<div className="mt-3 space-y-2">
<div className="flex items-center gap-2">
<div className="flex-1 h-1.5 rounded-full bg-charcoal-outline overflow-hidden">
<motion.div
className={`h-full ${passwordStrength.color}`}
initial={{ width: 0 }}
animate={{ width: `${(passwordStrength.score / 5) * 100}%` }}
transition={{ duration: 0.3 }}
/>
</div>
<span className={`text-xs font-medium ${
passwordStrength.score <= 1 ? 'text-red-400' :
passwordStrength.score <= 2 ? 'text-warning-amber' :
passwordStrength.score <= 3 ? 'text-primary-blue' :
'text-performance-green'
}`}>
{passwordStrength.label}
</span>
</div>
<div className="grid grid-cols-2 gap-1">
{passwordRequirements.map((req, index) => (
<div key={index} className="flex items-center gap-1.5 text-xs">
{req.met ? (
<Check className="w-3 h-3 text-performance-green" />
) : (
<X className="w-3 h-3 text-gray-500" />
)}
<span className={req.met ? 'text-gray-300' : 'text-gray-500'}>
{req.label}
</span>
</div>
))}
</div>
</div>
)}
</div>
{/* Confirm Password */}
<div>
<label htmlFor="confirmPassword" className="block text-sm font-medium text-gray-300 mb-2">
Confirm Password
</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
id="confirmPassword"
type={showConfirmPassword ? 'text' : 'password'}
value={formData.confirmPassword}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFormData({ ...formData, confirmPassword: e.target.value })}
error={!!errors.confirmPassword}
errorMessage={errors.confirmPassword}
placeholder="••••••••"
disabled={loading}
className="pl-10 pr-10"
autoComplete="new-password"
/>
<button
type="button"
onClick={() => setShowConfirmPassword(!showConfirmPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300"
>
{showConfirmPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</button>
</div>
{formData.confirmPassword && formData.password === formData.confirmPassword && (
<p className="mt-1 text-xs text-performance-green flex items-center gap-1">
<Check className="w-3 h-3" /> Passwords match
</p>
)}
</div>
{/* Error Message */}
<AnimatePresence>
{errors.submit && (
<motion.div
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
className="flex items-start gap-3 p-3 rounded-lg bg-red-500/10 border border-red-500/30"
>
<AlertCircle className="w-5 h-5 text-red-400 flex-shrink-0 mt-0.5" />
<p className="text-sm text-red-400">{errors.submit}</p>
</motion.div>
)}
</AnimatePresence>
{/* Submit Button */}
<Button
type="submit"
variant="primary"
disabled={loading}
className="w-full flex items-center justify-center gap-2"
>
{loading ? (
<>
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
Creating account...
</>
) : (
<>
<UserPlus className="w-4 h-4" />
Create Account
</>
)}
</Button>
</form>
{/* Divider */}
<div className="relative my-6">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-charcoal-outline" />
</div>
<div className="relative flex justify-center text-xs">
<span className="px-4 bg-iron-gray text-gray-500">or sign up with</span>
</div>
</div>
{/* iRacing Signup */}
<motion.button
type="button"
onClick={handleDemoLogin}
disabled={loading}
whileHover={{ scale: 1.01 }}
whileTap={{ scale: 0.99 }}
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"
>
Sign in
</Link>
</p>
</Card>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login (iRacing)</span>
<ChevronRight className="w-4 h-4 text-gray-500 group-hover:translate-x-0.5 transition-transform" />
</motion.button>
{/* Footer */}
<p className="mt-6 text-center text-xs text-gray-500">
By creating an account, you agree to our{' '}
<Link href="/terms" className="text-gray-400 hover:underline">Terms of Service</Link>
{' '}and{' '}
<Link href="/privacy" className="text-gray-400 hover:underline">Privacy Policy</Link>
</p>
{/* Login Link */}
<p className="mt-6 text-center text-sm text-gray-400">
Already have an account?{' '}
<Link
href={`/auth/login${returnTo !== '/onboarding' ? `?returnTo=${encodeURIComponent(returnTo)}` : ''}`}
className="text-primary-blue hover:underline font-medium"
>
Sign in
</Link>
</p>
</Card>
{/* Footer */}
<p className="mt-6 text-center text-xs text-gray-500">
By creating an account, you agree to our{' '}
<Link href="/terms" className="text-gray-400 hover:underline">Terms of Service</Link>
{' '}and{' '}
<Link href="/privacy" className="text-gray-400 hover:underline">Privacy Policy</Link>
</p>
{/* Mobile Role Info */}
<div className="mt-8 lg:hidden">
<p className="text-center text-xs text-gray-500 mb-4">One account for all roles</p>
<div className="flex justify-center gap-6">
{USER_ROLES.map((role) => (
<div key={role.title} className="flex flex-col items-center">
<div className={`w-8 h-8 rounded-lg bg-${role.color}/20 flex items-center justify-center mb-1`}>
<role.icon className={`w-4 h-4 text-${role.color}`} />
</div>
<span className="text-xs text-gray-500">{role.title}</span>
</div>
))}
</div>
</div>
</div>
</div>
</main>
);