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:
zetaloop
2026-05-01 04:20:02 +08:00
parent 86d1b05271
commit d76866ac3b
2 changed files with 81 additions and 73 deletions
+4 -4
View File
@@ -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
}