From 5d3a77133d8404f47832ea8c9bc38ffc16c02e74 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sat, 7 Jun 2025 19:47:22 +0200 Subject: [PATCH] feat: fetch api service state --- web/src/store/oauth.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/web/src/store/oauth.ts b/web/src/store/oauth.ts index 24c9a55..9906cad 100644 --- a/web/src/store/oauth.ts +++ b/web/src/store/oauth.ts @@ -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; + + fetchApiService: () => Promise; } export const useOAuth = create((set, get) => ({ @@ -21,6 +28,25 @@ export const useOAuth = create((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;