feat(auth): add pending action queue and api auth wrapper

This commit is contained in:
zetaloop
2026-02-22 08:29:18 +08:00
parent dc629c9472
commit 8ce3b8a8b5
3 changed files with 38 additions and 7 deletions
+24
View File
@@ -0,0 +1,24 @@
import { useLoginDialogStore } from "@/store/login-dialog"
type RequestExecutor<T> = () => Promise<T>
interface RequestOptions {
onUnauthorized?: () => void
}
export async function requestWithAuth<T>(executor: RequestExecutor<T>, options?: RequestOptions) {
try {
return await executor()
} catch (error) {
if (error instanceof Error && error.message === "UNAUTHORIZED") {
if (options?.onUnauthorized) {
useLoginDialogStore.getState().openLoginDialog(options.onUnauthorized)
} else {
useLoginDialogStore.getState().openLoginDialog()
}
return null
}
throw error
}
}