mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
28 lines
534 B
TypeScript
28 lines
534 B
TypeScript
import token from '~/pages/api/auth/Token';
|
|
|
|
export default class SecurityClient {
|
|
static #token = '';
|
|
|
|
constructor() {}
|
|
|
|
static setToken(token: string) {
|
|
this.#token = token;
|
|
}
|
|
|
|
static async fetchCall(
|
|
resource: RequestInfo,
|
|
options?: RequestInit | undefined
|
|
) {
|
|
const req = new Request(resource, options);
|
|
|
|
if (this.#token == '') {
|
|
this.setToken(await token());
|
|
}
|
|
|
|
if (this.#token) {
|
|
req.headers.set('Authorization', 'Bearer ' + this.#token);
|
|
return fetch(req);
|
|
}
|
|
}
|
|
}
|