fix(auth): persist login state to localStorage
Save user data, role, and verification status on login so that page refresh does not lose the session. On mount, AuthBootstrap always verifies against the backend via getCurrentUserForLogin to confirm the cookie JWT is still valid. Remove unused verification store methods (submitVerification, approveVerification, rejectVerification) — the verify page already calls lib/api/users.ts directly.
This commit is contained in:
+4
-4
@@ -12,11 +12,11 @@ import { Toaster } from "sonner"
|
||||
|
||||
function AuthBootstrap() {
|
||||
const login = useAuthStore((s) => s.login)
|
||||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated)
|
||||
const logout = useAuthStore((s) => s.logout)
|
||||
const tried = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (tried.current || isAuthenticated) return
|
||||
if (tried.current) return
|
||||
tried.current = true
|
||||
|
||||
getCurrentUserForLogin()
|
||||
@@ -24,9 +24,9 @@ function AuthBootstrap() {
|
||||
login(user, user.verifiedRoles ?? ["consumer"])
|
||||
})
|
||||
.catch(() => {
|
||||
// no valid session — stay logged out
|
||||
logout()
|
||||
})
|
||||
}, [login, isAuthenticated])
|
||||
}, [login, logout])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user