feat: global login dialog with useRequireAuth hook for 401 auth gating

This commit is contained in:
zetaloop
2026-02-20 18:50:46 +08:00
parent 0403c12ccc
commit 07754069c1
5 changed files with 53 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
"use client"
import { useCallback } from "react"
import { useAuthStore } from "@/store/auth"
import { useLoginDialogStore } from "@/store/login-dialog"
export function useRequireAuth() {
const isAuthenticated = useAuthStore((s) => s.isAuthenticated)
const openLoginDialog = useLoginDialogStore((s) => s.openLoginDialog)
const requireAuth = useCallback(
(action: () => void) => {
if (isAuthenticated) {
action()
} else {
openLoginDialog()
}
},
[isAuthenticated, openLoginDialog],
)
return { isAuthenticated, requireAuth }
}