feat: fetch api service state

This commit is contained in:
2025-06-07 19:47:22 +02:00
parent 44592ebc08
commit 5d3a77133d

View File

@ -1,4 +1,6 @@
import { getApiServiceCID } from "@/api/admin/apiServices";
import { codeApi } from "@/api/code";
import type { ApiService } from "@/types";
import { create } from "zustand";
export interface OAuthState {
@ -9,8 +11,13 @@ export interface OAuthState {
state: string;
nonce: string;
apiService: ApiService | null;
fetching: boolean;
parseSearchParams: (params: URLSearchParams) => void;
selectSession: (token: string) => Promise<void>;
fetchApiService: () => Promise<void>;
}
export const useOAuth = create<OAuthState>((set, get) => ({
@ -21,6 +28,25 @@ export const useOAuth = create<OAuthState>((set, get) => ({
state: "",
nonce: "",
apiService: null,
fetching: false,
fetchApiService: async () => {
const { clientID } = get();
if (!clientID) return;
set({ fetching: true });
try {
const response = await getApiServiceCID(clientID);
set({ apiService: response });
} catch (err) {
console.log("ERR: Failed to fetch api service by client id:", err);
} finally {
set({ fetching: false });
}
},
parseSearchParams: (params) => {
if (get().active) return;