diff --git a/apps/dashboard/src/components/App/index.tsx b/apps/dashboard/src/components/App/index.tsx index 4050dbcd676055a1843f5f1387b390b1ed5aa53a..f539f1e742a51280916669cee85507eb4201b31b 100644 --- a/apps/dashboard/src/components/App/index.tsx +++ b/apps/dashboard/src/components/App/index.tsx @@ -20,7 +20,7 @@ const App = observer(() => { }, wsUrl: config.OCMENGINE_WS_URL, httpUrl: config.OCMENGINE_HTTP_URL, - getToken: async () => auth.getToken() || "", + getAuthorization: async () => config.OCMENGINE_AUTHORIZATION || `Bearer ${auth.getToken()}` || "", }); setAppLoading(false); }, [auth]); diff --git a/apps/dashboard/src/hooks/auth/useAuth.ts b/apps/dashboard/src/hooks/auth/useAuth.ts index 2eda398084e8481dfe9592d8a7ca8ffbacd47cc4..febc8e96a96bcb46dc9e4d2b5946a8aa7958b679 100644 --- a/apps/dashboard/src/hooks/auth/useAuth.ts +++ b/apps/dashboard/src/hooks/auth/useAuth.ts @@ -1,4 +1,5 @@ import { useEffect, useState } from "react"; +import getConfig from "@dashboard/utils/getConfig"; const LS_KEY = "token"; @@ -30,6 +31,12 @@ const useAuth = () => { const [loading, setLoading] = useState(true); useEffect(() => { + if (getConfig().OCMENGINE_AUTHORIZATION) { + setAuthorized(true); + setLoading(false); + return; + } + const lsToken = localStorage.getItem(LS_KEY); if (lsToken) { if (isJwtValid(lsToken)) { diff --git a/apps/dashboard/src/main.tsx b/apps/dashboard/src/main.tsx index 0e7223c97cac7b22d081534ea73cbf8e9fa5415f..9b91aa72dbb97fed10977a2c257ad854040c7cf9 100644 --- a/apps/dashboard/src/main.tsx +++ b/apps/dashboard/src/main.tsx @@ -19,7 +19,7 @@ const config = getConfig(); setOcmEngineConfig({ wsUrl: config.OCMENGINE_WS_URL, httpUrl: config.OCMENGINE_HTTP_URL, - getToken: async () => "", + getAuthorization: async () => "", }); setTsaConfig({ diff --git a/apps/dashboard/src/utils/getConfig.ts b/apps/dashboard/src/utils/getConfig.ts index 835d16a740797157eb4f602560657a4e6cee97fc..467aac0613bfce8734661d5d4ad0353eb97d9661 100644 --- a/apps/dashboard/src/utils/getConfig.ts +++ b/apps/dashboard/src/utils/getConfig.ts @@ -3,10 +3,12 @@ export interface Config { OCMENGINE_WS_URL: string; TSA_URL: string; BASE_PATH: string; + OCMENGINE_AUTHORIZATION: string | null | undefined; } const lsHttp = localStorage.getItem("OCMENGINE_HTTP_URL"); const lsWs = localStorage.getItem("OCMENGINE_WS_URL"); +const authorization = localStorage.getItem("OCMENGINE_AUTHORIZATION"); const tsaHttp = localStorage.getItem("TSA_URL"); export const getConfig = (): Config => { return { @@ -14,6 +16,7 @@ export const getConfig = (): Config => { OCMENGINE_WS_URL: lsWs || window.OCMENGINE_WS_URL, TSA_URL: tsaHttp || window.TSA_URL, BASE_PATH: window.BASE_PATH, + OCMENGINE_AUTHORIZATION: authorization }; }; diff --git a/libs/clients/src/ocmengine-client.ts b/libs/clients/src/ocmengine-client.ts index 42d2f94d0b16386c4a8445314137c4148079ae42..3f2b2e9d5bbf733f06bf4d54fdf4b68802596bf2 100644 --- a/libs/clients/src/ocmengine-client.ts +++ b/libs/clients/src/ocmengine-client.ts @@ -27,7 +27,7 @@ export interface Config { onUnauthorized?: () => void; wsUrl: string; httpUrl: string; - getToken: () => Promise<string>; + getAuthorization: () => Promise<string>; } let config: Config | null = null; @@ -129,12 +129,12 @@ class ApiClient { // this._listen(); } - public async getToken(): Promise<string> { + public async getAuthorization(): Promise<string> { if (!config) { throw new Error("ApiClient: Please call setConfig before calling api"); } - return config.getToken(); + return config.getAuthorization(); } private async _fetch(url: RequestInfo, init?: RequestInit): Promise<unknown> { @@ -145,7 +145,7 @@ class ApiClient { init = Object.assign({}, init, { headers: { ...(init?.headers || {}), - Authorization: `Bearer ${await config.getToken()}`, + Authorization: await config.getAuthorization(), }, });