remove demo code

This commit is contained in:
2026-01-03 11:38:51 +01:00
parent 2f21dc4595
commit 9a7efa496f
38 changed files with 1535 additions and 1157 deletions

View File

@@ -12,9 +12,7 @@ import {
LogIn,
AlertCircle,
Flag,
Gamepad2,
Shield,
ChevronRight,
} from 'lucide-react';
import Card from '@/components/ui/Card';
@@ -97,31 +95,6 @@ export default function LoginPage() {
},
});
const handleDemoLogin = async () => {
try {
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();
// Get rememberMe value safely
const rememberMe = formState.fields.rememberMe?.value ?? false;
await authService.demoLogin({
role: 'driver',
rememberMe,
});
await new Promise(resolve => setTimeout(resolve, 500));
router.push(returnTo);
} catch (error) {
setFormError('Demo login failed. Please try again.');
logErrorWithContext(error, {
component: 'LoginPage',
action: 'demo-login',
});
}
};
return (
<main className="min-h-screen bg-deep-graphite flex">
{/* Background Pattern */}
@@ -164,8 +137,7 @@ export default function LoginPage() {
<span>Secure login</span>
</div>
<div className="flex items-center gap-2">
<Gamepad2 className="w-4 h-4" />
<span>iRacing verified</span>
<span className="text-sm">iRacing verified</span>
</div>
</div>
</div>
@@ -317,20 +289,6 @@ export default function LoginPage() {
</div>
</div>
{/* Demo Login */}
<motion.button
type="button"
onClick={handleDemoLogin}
disabled={formState.isSubmitting}
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"
>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login</span>
<ChevronRight className="w-4 h-4 text-gray-500 group-hover:translate-x-0.5 transition-transform" />
</motion.button>
{/* Sign Up Link */}
<p className="mt-6 text-center text-sm text-gray-400">
Don't have an account?{' '}

View File

@@ -15,13 +15,11 @@ import {
User,
Check,
X,
Gamepad2,
Loader2,
Car,
Users,
Trophy,
Shield,
ChevronRight,
Sparkles,
} from 'lucide-react';
@@ -239,26 +237,6 @@ export default function SignupPage() {
}
};
const handleDemoLogin = async () => {
setLoading(true);
try {
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));
// Always redirect to dashboard after demo login
router.push('/dashboard');
} catch {
setErrors({
submit: 'Demo login failed. Please try again.',
});
setLoading(false);
}
};
// Show loading while checking auth
if (checkingAuth) {
return (
@@ -344,7 +322,6 @@ export default function SignupPage() {
<span>Secure signup</span>
</div>
<div className="flex items-center gap-2">
<Gamepad2 className="w-4 h-4" />
<span>iRacing integration</span>
</div>
</div>
@@ -596,24 +573,10 @@ export default function SignupPage() {
<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>
<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"
>
<Gamepad2 className="w-5 h-5 text-primary-blue" />
<span>Demo Login</span>
<ChevronRight className="w-4 h-4 text-gray-500 group-hover:translate-x-0.5 transition-transform" />
</motion.button>
{/* Login Link */}
<p className="mt-6 text-center text-sm text-gray-400">
Already have an account?{' '}

View File

@@ -140,29 +140,6 @@ export default function SponsorSignupPage() {
const [errors, setErrors] = useState<Record<string, string>>({});
const [submitting, setSubmitting] = useState(false);
const handleDemoLogin = async () => {
setSubmitting(true);
try {
// Use the demo login API instead of setting cookies
const response = await fetch('/api/auth/demo-login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ role: 'sponsor' }),
});
if (!response.ok) {
throw new Error('Demo login failed');
}
router.push('/sponsor/dashboard');
} catch (error) {
console.error('Demo login failed:', error);
alert('Demo login failed. Please check the API server status.');
} finally {
setSubmitting(false);
}
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
@@ -206,22 +183,47 @@ export default function SponsorSignupPage() {
setSubmitting(true);
try {
// For demo purposes, use the demo login API with sponsor role
// In production, this would create a real sponsor account
const response = await fetch('/api/auth/demo-login', {
// Create a sponsor account using the normal signup flow
// The backend will handle creating the sponsor user with the appropriate role
const response = await fetch('/api/auth/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ role: 'sponsor' }),
body: JSON.stringify({
email: formData.contactEmail,
password: formData.password,
displayName: formData.companyName,
// Additional sponsor-specific data
sponsorData: {
companyName: formData.companyName,
websiteUrl: formData.websiteUrl,
interests: formData.interests,
},
}),
});
if (!response.ok) {
throw new Error('Signup failed');
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.message || 'Signup failed');
}
// Auto-login after successful signup
const loginResponse = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: formData.contactEmail,
password: formData.password,
}),
});
if (!loginResponse.ok) {
throw new Error('Auto-login failed');
}
router.push('/sponsor/dashboard');
} catch (err) {
console.error('Sponsor signup failed:', err);
alert('Registration failed. Try again.');
alert('Registration failed. ' + (err instanceof Error ? err.message : 'Try again.'));
} finally {
setSubmitting(false);
}
@@ -263,17 +265,6 @@ export default function SponsorSignupPage() {
<ArrowRight className="w-5 h-5 ml-2" />
</Button>
</div>
{/* Demo Login */}
<div className="mt-6">
<button
onClick={handleDemoLogin}
disabled={submitting}
className="text-sm text-gray-500 hover:text-gray-400 transition-colors disabled:opacity-50"
>
{submitting ? 'Loading...' : 'Try demo sponsor account →'}
</button>
</div>
</SponsorHero>
{/* Platform Stats */}
@@ -529,13 +520,6 @@ export default function SponsorSignupPage() {
Create one
</button>
</p>
<button
onClick={handleDemoLogin}
disabled={submitting}
className="w-full text-sm text-gray-500 hover:text-gray-400 text-center"
>
Or try the demo account
</button>
</div>
</Card>
</div>

View File

@@ -3,7 +3,7 @@
import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId';
import { useNotifications } from '@/components/notifications/NotificationProvider';
import type { NotificationVariant } from '@/components/notifications/notificationTypes';
import { Wrench, ChevronDown, ChevronUp, X, MessageSquare, Activity, LogIn, AlertTriangle } from 'lucide-react';
import { Wrench, ChevronDown, ChevronUp, X, MessageSquare, Activity, AlertTriangle } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { ApiConnectionMonitor } from '@/lib/api/base/ApiConnectionMonitor';
@@ -16,10 +16,9 @@ import { NotificationTypeSection } from './sections/NotificationTypeSection';
import { UrgencySection } from './sections/UrgencySection';
import { NotificationSendSection } from './sections/NotificationSendSection';
import { APIStatusSection } from './sections/APIStatusSection';
import { LoginSection } from './sections/LoginSection';
// Import types
import type { DemoNotificationType, DemoUrgency, LoginMode } from './types';
import type { DemoNotificationType, DemoUrgency } from './types';
export default function DevToolbar() {
const router = useRouter();
@@ -30,8 +29,6 @@ export default function DevToolbar() {
const [selectedUrgency, setSelectedUrgency] = useState<DemoUrgency>('toast');
const [sending, setSending] = useState(false);
const [lastSent, setLastSent] = useState<string | null>(null);
const [loginMode, setLoginMode] = useState<LoginMode>('none');
const [loggingIn, setLoggingIn] = useState(false);
// API Status Monitoring State
const [apiStatus, setApiStatus] = useState(() => ApiConnectionMonitor.getInstance().getStatus());
@@ -47,77 +44,6 @@ export default function DevToolbar() {
const currentDriverId = useEffectiveDriverId();
// Sync login mode with actual session state on mount
useEffect(() => {
if (typeof document !== 'undefined') {
// Check for actual session cookie first
const cookies = document.cookie.split(';');
const sessionCookie = cookies.find(c => c.trim().startsWith('gp_session='));
if (sessionCookie) {
// User has a session cookie, check if it's valid by calling the API
fetch('/api/auth/session', {
method: 'GET',
credentials: 'include'
})
.then(res => {
if (res.ok) {
return res.json();
}
throw new Error('No valid session');
})
.then(session => {
if (session && session.user) {
// Determine login mode based on user email patterns
const email = session.user.email?.toLowerCase() || '';
const displayName = session.user.displayName?.toLowerCase() || '';
const role = (session.user as any).role;
let mode: LoginMode = 'none';
// First check session.role if available
if (role) {
if (role === 'sponsor') mode = 'sponsor';
else if (role === 'league-owner') mode = 'league-owner';
else if (role === 'league-steward') mode = 'league-steward';
else if (role === 'league-admin') mode = 'league-admin';
else if (role === 'system-owner') mode = 'system-owner';
else if (role === 'super-admin') mode = 'super-admin';
else if (role === 'driver') mode = 'driver';
}
// Fallback to email patterns
else if (email.includes('sponsor') || displayName.includes('sponsor')) {
mode = 'sponsor';
} else if (email.includes('league-owner') || displayName.includes('owner')) {
mode = 'league-owner';
} else if (email.includes('league-steward') || displayName.includes('steward')) {
mode = 'league-steward';
} else if (email.includes('league-admin') || displayName.includes('admin')) {
mode = 'league-admin';
} else if (email.includes('system-owner') || displayName.includes('system owner')) {
mode = 'system-owner';
} else if (email.includes('super-admin') || displayName.includes('super admin')) {
mode = 'super-admin';
} else if (email.includes('driver') || displayName.includes('demo')) {
mode = 'driver';
}
setLoginMode(mode);
} else {
setLoginMode('none');
}
})
.catch(() => {
// Session invalid or expired
setLoginMode('none');
});
} else {
// No session cookie means not logged in
setLoginMode('none');
}
}
}, []);
// API Status Monitoring Effects
useEffect(() => {
const monitor = ApiConnectionMonitor.getInstance();
@@ -235,54 +161,6 @@ export default function DevToolbar() {
}
};
const handleDemoLogin = async (role: LoginMode) => {
if (role === 'none') return;
setLoggingIn(true);
try {
// Use the demo login API
const response = await fetch('/api/auth/demo-login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ role }),
});
if (!response.ok) {
throw new Error('Demo login failed');
}
setLoginMode(role);
// Navigate based on role
if (role === 'sponsor') {
window.location.href = '/sponsor/dashboard';
} else {
// For driver and league roles, go to dashboard
window.location.href = '/dashboard';
}
} catch (error) {
alert('Demo login failed. Please check the API server status.');
} finally {
setLoggingIn(false);
}
};
const handleLogout = async () => {
setLoggingIn(true);
try {
// Call logout API
await fetch('/api/auth/logout', { method: 'POST' });
setLoginMode('none');
// Refresh to update all components
window.location.href = '/';
} catch (error) {
alert('Logout failed. Please check the API server status.');
} finally {
setLoggingIn(false);
}
};
// Only show in development
if (process.env.NODE_ENV === 'production') {
return null;
@@ -435,21 +313,6 @@ export default function DevToolbar() {
/>
</Accordion>
{/* Login Section - Accordion */}
<Accordion
title="Demo Login"
icon={<LogIn className="w-4 h-4 text-gray-400" />}
isOpen={openAccordion === 'login'}
onToggle={() => setOpenAccordion(openAccordion === 'login' ? null : 'login')}
>
<LoginSection
loginMode={loginMode}
loggingIn={loggingIn}
onDemoLogin={handleDemoLogin}
onLogout={handleLogout}
/>
</Accordion>
{/* Error Stats Section - Accordion */}
<Accordion
title="Error Stats"

View File

@@ -1,79 +0,0 @@
'use client';
import { LogIn, LogOut, User, Shield, Building2 } from 'lucide-react';
import type { LoginMode } from '../types';
interface LoginSectionProps {
loginMode: LoginMode;
loggingIn: boolean;
onDemoLogin: (role: LoginMode) => void;
onLogout: () => void;
}
export function LoginSection({ loginMode, loggingIn, onDemoLogin, onLogout }: LoginSectionProps) {
const loginOptions = [
{ mode: 'driver' as LoginMode, label: 'Driver', icon: User, color: 'primary-blue', emoji: null },
{ mode: 'league-owner' as LoginMode, label: 'League Owner', icon: null, color: 'purple-500', emoji: '👑' },
{ mode: 'league-steward' as LoginMode, label: 'Steward', icon: Shield, color: 'amber-500', emoji: null },
{ mode: 'league-admin' as LoginMode, label: 'Admin', icon: null, color: 'red-500', emoji: '⚙️' },
{ mode: 'sponsor' as LoginMode, label: 'Sponsor', icon: Building2, color: 'performance-green', emoji: null },
{ mode: 'system-owner' as LoginMode, label: 'System Owner', icon: null, color: 'indigo-500', emoji: '👑' },
{ mode: 'super-admin' as LoginMode, label: 'Super Admin', icon: null, color: 'pink-500', emoji: '⚡' },
];
return (
<div>
<div className="flex items-center gap-2 mb-3">
<LogIn className="w-4 h-4 text-gray-400" />
<span className="text-xs font-semibold text-gray-400 uppercase tracking-wide">
Demo Login
</span>
</div>
<div className="space-y-2">
{loginOptions.map((option) => {
const Icon = option.icon;
const isSelected = loginMode === option.mode;
return (
<button
key={option.mode}
onClick={() => onDemoLogin(option.mode)}
disabled={loggingIn || isSelected}
className={`
w-full flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-all
${isSelected
? `bg-${option.color}/20 border-${option.color}/50 text-${option.color}`
: 'bg-iron-gray/30 border-charcoal-outline text-gray-300 hover:bg-iron-gray/50'
}
disabled:opacity-50 disabled:cursor-not-allowed
`}
>
{option.emoji ? (
<span className="text-xs">{option.emoji}</span>
) : Icon ? (
<Icon className="w-4 h-4" />
) : null}
{isSelected ? `${option.label}` : `Login as ${option.label}`}
</button>
);
})}
{loginMode !== 'none' && (
<button
onClick={onLogout}
disabled={loggingIn}
className="w-full flex items-center gap-2 px-3 py-2 rounded-lg border border-red-500/30 bg-red-500/10 text-red-400 text-sm font-medium hover:bg-red-500/20 transition-all disabled:opacity-50 disabled:cursor-not-allowed"
>
<LogOut className="w-4 h-4" />
Logout
</button>
)}
</div>
<p className="text-[10px] text-gray-600 mt-2">
Test different user roles for demo purposes. Dashboard works for all roles.
</p>
</div>
);
}

View File

@@ -2,7 +2,6 @@ import type { NotificationVariant } from '@/components/notifications/notificatio
export type DemoNotificationType = 'protest_filed' | 'defense_requested' | 'vote_required' | 'race_performance_summary' | 'race_final_results';
export type DemoUrgency = 'silent' | 'toast' | 'modal';
export type LoginMode = 'none' | 'driver' | 'sponsor' | 'league-owner' | 'league-steward' | 'league-admin' | 'system-owner' | 'super-admin';
export interface NotificationOption {
type: DemoNotificationType;

View File

@@ -4,7 +4,6 @@ import { LoginParamsDTO } from '../../types/generated/LoginParamsDTO';
import { SignupParamsDTO } from '../../types/generated/SignupParamsDTO';
import { ForgotPasswordDTO } from '../../types/generated/ForgotPasswordDTO';
import { ResetPasswordDTO } from '../../types/generated/ResetPasswordDTO';
import { DemoLoginDTO } from '../../types/generated/DemoLoginDTO';
/**
* Auth API Client
@@ -43,9 +42,4 @@ export class AuthApiClient extends BaseApiClient {
resetPassword(params: ResetPasswordDTO): Promise<{ message: string }> {
return this.post<{ message: string }>('/auth/reset-password', params);
}
/** Demo login (development only) */
demoLogin(params: DemoLoginDTO): Promise<AuthSessionDTO> {
return this.post<AuthSessionDTO>('/auth/demo-login', params);
}
}
}

View File

@@ -83,7 +83,6 @@ export function getPublicRoutes(): readonly string[] {
'/api/auth/login',
'/api/auth/forgot-password',
'/api/auth/reset-password',
'/api/auth/demo-login',
'/api/auth/session',
'/api/auth/logout',
'/auth/login',

View File

@@ -4,7 +4,6 @@ import type { LoginParamsDTO } from '../../types/generated/LoginParamsDTO';
import type { SignupParamsDTO } from '../../types/generated/SignupParamsDTO';
import type { ForgotPasswordDTO } from '../../types/generated/ForgotPasswordDTO';
import type { ResetPasswordDTO } from '../../types/generated/ResetPasswordDTO';
import type { DemoLoginDTO } from '../../types/generated/DemoLoginDTO';
/**
* Auth Service
@@ -73,16 +72,4 @@ export class AuthService {
throw error;
}
}
/**
* Demo login (development only)
*/
async demoLogin(params: DemoLoginDTO): Promise<SessionViewModel> {
try {
const dto = await this.apiClient.demoLogin(params);
return new SessionViewModel(dto.user);
} catch (error) {
throw error;
}
}
}

View File

@@ -1,7 +0,0 @@
import { describe, it, expect } from 'vitest';
describe('types/generated/DemoLoginDTO', () => {
it('should be defined', () => {
expect(true).toBe(true);
});
});

View File

@@ -1,11 +0,0 @@
/**
* Auto-generated DTO from OpenAPI spec
* Spec SHA256: 486d4cc42e94a6bbc53e2ed3b770a221d7e7a6e41f684929fd050ca0f62b5849
* This file is generated by scripts/generate-api-types.ts
* Do not edit manually - regenerate using: npm run api:generate-types
*/
export interface DemoLoginDTO {
role: string;
rememberMe?: boolean;
}

View File

@@ -46,7 +46,6 @@ export type { DashboardRaceSummaryDTO } from './DashboardRaceSummaryDTO';
export type { DashboardRecentResultDTO } from './DashboardRecentResultDTO';
export type { DeleteMediaOutputDTO } from './DeleteMediaOutputDTO';
export type { DeletePrizeResultDTO } from './DeletePrizeResultDTO';
export type { DemoLoginDTO } from './DemoLoginDTO';
export type { DriverDTO } from './DriverDTO';
export type { DriverLeaderboardItemDTO } from './DriverLeaderboardItemDTO';
export type { DriverProfileAchievementDTO } from './DriverProfileAchievementDTO';
@@ -247,4 +246,4 @@ export type { WizardErrorsDTO } from './WizardErrorsDTO';
export type { WizardErrorsScoringDTO } from './WizardErrorsScoringDTO';
export type { WizardErrorsStructureDTO } from './WizardErrorsStructureDTO';
export type { WizardErrorsTimingsDTO } from './WizardErrorsTimingsDTO';
export type { WizardStepDTO } from './WizardStepDTO';
export type { WizardStepDTO } from './WizardStepDTO';