feat: adding background jobs ui page and apis - requires user is_admin to be set to true

This commit is contained in:
allanice001
2025-11-04 23:52:37 +00:00
parent 91686c1ea4
commit c41af60b26
97 changed files with 11135 additions and 138 deletions

21
ui/src/auth/logout.ts Normal file
View File

@@ -0,0 +1,21 @@
import { authStore } from "@/auth/store.ts"
import type { DtoLogoutRequest } from "@/sdk"
import { makeAuthApi } from "@/sdkClient.ts"
export async function logoutEverywhere(): Promise<void> {
const tokens = authStore.get()
if (!tokens?.refresh_token) {
authStore.logout()
return
}
try {
const body: DtoLogoutRequest = { refresh_token: tokens.refresh_token } as DtoLogoutRequest
await makeAuthApi().logout({ body })
} catch (err) {
console.warn("Logout API failed; clearing local state anyway", err)
} finally {
authStore.logout()
}
}

View File

@@ -1,17 +0,0 @@
import { useSyncExternalStore } from "react"
import { authStore, type TokenPair } from "@/auth/store.ts"
export const useAuth = () => {
const tokens = useSyncExternalStore<TokenPair | null>(
(cb) => authStore.subscribe(cb),
() => authStore.get(),
() => authStore.get() // server snapshot (SSR)
)
return {
tokens,
authed: !!tokens?.access_token,
isExpired: authStore.isExpired(),
willExpireSoon: authStore.willExpireSoon(),
}
}