refactor(auth): support async deferred actions for login gating
Allow deferred login actions to return promises and execute them safely without violating lint rules. Also initialize order detail timer state without impure render-time Date.now calls so React hook purity checks pass.
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ import { useLoginDialogStore } from "@/store/login-dialog"
|
||||
type RequestExecutor<T> = () => Promise<T>
|
||||
|
||||
interface RequestOptions {
|
||||
onUnauthorized?: () => void
|
||||
onUnauthorized?: () => void | Promise<void>
|
||||
}
|
||||
|
||||
export async function requestWithAuth<T>(executor: RequestExecutor<T>, options?: RequestOptions) {
|
||||
|
||||
@@ -9,9 +9,9 @@ export function useRequireAuth() {
|
||||
const openLoginDialog = useLoginDialogStore((s) => s.openLoginDialog)
|
||||
|
||||
const requireAuth = useCallback(
|
||||
(action: () => void) => {
|
||||
(action: () => void | Promise<void>) => {
|
||||
if (isAuthenticated) {
|
||||
action()
|
||||
void action()
|
||||
} else {
|
||||
openLoginDialog(action)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user