Compare commits

...

3 Commits

Author SHA1 Message Date
Barcode Betty c77b88988b chore: retrigger CI on correct commit
Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-19 16:01:28 +00:00
Barcode Betty 7b85924018 fix: remove unused navigate variable from Login.tsx
Remove const navigate = useNavigate() and the useNavigate import since
the success path now uses window.location.href = '/' instead.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-19 15:54:12 +00:00
Barcode Betty 70e5a232c9 fix: resolve sign-in redirect race condition in Login.tsx
Use window.location.href = '/' instead of React Router navigate() after
successful sign-in. Better-Auth's useSession() hasn't updated its internal
cache when navigate() fires, causing ProtectedRoute to see a null session
and redirect back to /login. A full page reload reinitializes useSession()
with fresh cookie-backed session state.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-19 15:22:37 +00:00
+5 -5
View File
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { Link, useNavigate } from 'react-router-dom'
import { Link } from 'react-router-dom'
import { authClient } from '../lib/auth-client.ts'
import { useAuthStore } from '../stores/auth.ts'
@@ -8,7 +8,6 @@ export function Login() {
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const navigate = useNavigate()
const setAuthenticated = useAuthStore((s) => s.setAuthenticated)
async function handleSubmit(e: React.FormEvent) {
@@ -31,11 +30,12 @@ export function Login() {
throw new Error(authError.message ?? 'Sign in failed')
}
// After successful signIn, force a session fetch to confirm the cookie is set
// before navigating to the protected route
// After successful signIn, force a full page reload so Better-Auth's
// useSession() reinitializes with fresh cookie-backed session state.
// Using React Router's navigate() races with Better-Auth's internal update.
const sessionResult = await authClient.getSession()
if (sessionResult.data) {
navigate('/')
window.location.href = '/'
} else {
setError('Sign in failed. Please try again.')
}