wip
This commit is contained in:
@@ -19,6 +19,7 @@ import Card from '@/components/ui/Card';
|
||||
import Button from '@/components/ui/Button';
|
||||
import Input from '@/components/ui/Input';
|
||||
import Heading from '@/components/ui/Heading';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
|
||||
interface FormErrors {
|
||||
email?: string;
|
||||
@@ -29,6 +30,7 @@ interface FormErrors {
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { refreshSession } = useAuth();
|
||||
const returnTo = searchParams.get('returnTo') ?? '/dashboard';
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -81,8 +83,9 @@ export default function LoginPage() {
|
||||
throw new Error(data.error || 'Login failed');
|
||||
}
|
||||
|
||||
// Refresh session in context so header updates immediately
|
||||
await refreshSession();
|
||||
router.push(returnTo);
|
||||
router.refresh();
|
||||
} catch (error) {
|
||||
setErrors({
|
||||
submit: error instanceof Error ? error.message : 'Login failed. Please try again.',
|
||||
@@ -94,9 +97,8 @@ export default function LoginPage() {
|
||||
const handleDemoLogin = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const authService = getAuthService();
|
||||
const { redirectUrl } = await authService.startIracingAuthRedirect(returnTo);
|
||||
router.push(redirectUrl);
|
||||
// Redirect to iRacing auth start route
|
||||
router.push(`/auth/iracing/start?returnTo=${encodeURIComponent(returnTo)}`);
|
||||
} catch (error) {
|
||||
setErrors({
|
||||
submit: 'Demo login failed. Please try again.',
|
||||
|
||||
Reference in New Issue
Block a user