From 0c34f9aa5706a082322a37dd651a888d5367d0e9 Mon Sep 17 00:00:00 2001 From: CartSnitch Engineer Bot Date: Tue, 31 Mar 2026 22:30:05 +0000 Subject: [PATCH] fix(auth): restore setAuthenticated in mock-auth catch block The try-block getSession() pattern is correct for real auth mode. The mock-auth catch block (VITE_MOCK_AUTH) still needs to set the Zustand flag so ProtectedRoute respects the authenticated state. Co-Authored-By: Paperclip --- src/pages/Login.tsx | 3 +++ src/pages/Register.tsx | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index 6ee9bcf..ae7fc0c 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -1,6 +1,7 @@ import { useState } from 'react' import { Link, useNavigate } from 'react-router-dom' import { authClient } from '../lib/auth-client.ts' +import { useAuthStore } from '../stores/auth.ts' export function Login() { const [email, setEmail] = useState('') @@ -8,6 +9,7 @@ export function Login() { const [error, setError] = useState('') const [loading, setLoading] = useState(false) const navigate = useNavigate() + const setAuthenticated = useAuthStore((s) => s.setAuthenticated) async function handleSubmit(e: React.FormEvent) { e.preventDefault() @@ -39,6 +41,7 @@ export function Login() { } } catch { if (import.meta.env.VITE_MOCK_AUTH === 'true') { + setAuthenticated(true) navigate('/') } else { setError('Invalid email or password. Please try again.') diff --git a/src/pages/Register.tsx b/src/pages/Register.tsx index a93317d..c75e2d6 100644 --- a/src/pages/Register.tsx +++ b/src/pages/Register.tsx @@ -1,6 +1,7 @@ import { useState } from 'react' import { Link, useNavigate } from 'react-router-dom' import { authClient } from '../lib/auth-client.ts' +import { useAuthStore } from '../stores/auth.ts' export function Register() { const [name, setName] = useState('') @@ -9,6 +10,7 @@ export function Register() { const [error, setError] = useState('') const [loading, setLoading] = useState(false) const navigate = useNavigate() + const setAuthenticated = useAuthStore((s) => s.setAuthenticated) async function handleSubmit(e: React.FormEvent) { e.preventDefault() @@ -47,6 +49,7 @@ export function Register() { } } catch { if (import.meta.env.VITE_MOCK_AUTH === 'true') { + setAuthenticated(true) navigate('/') } else { setError('Registration failed. Please try again.')