fix: sync verification state with auth guards

This commit is contained in:
zetaloop
2026-02-21 15:53:46 +08:00
parent 6469811382
commit 6ed8620ca6
5 changed files with 70 additions and 7 deletions
+8 -2
View File
@@ -1,6 +1,6 @@
"use client"
import { useEffect } from "react"
import { useEffect, useRef } from "react"
import { Button } from "@/components/ui/button"
import { useAuthStore } from "@/store/auth"
import { useLoginDialogStore } from "@/store/login-dialog"
@@ -12,9 +12,15 @@ interface AuthGuardProps {
export function AuthGuard({ children }: AuthGuardProps) {
const isAuthenticated = useAuthStore((s) => s.isAuthenticated)
const openLoginDialog = useLoginDialogStore((s) => s.openLoginDialog)
const hasTriggered = useRef(false)
useEffect(() => {
if (!isAuthenticated) {
if (isAuthenticated) {
hasTriggered.current = false
return
}
if (!hasTriggered.current) {
hasTriggered.current = true
openLoginDialog()
}
}, [isAuthenticated, openLoginDialog])