Merge pull request #59 from reginaldbondoc/I-36-remove-dependency-to-path-const

I-36 Remove dependency to PATH const
This commit is contained in:
BlackMagiq
2022-11-30 18:48:29 -05:00
committed by GitHub
57 changed files with 54 additions and 125 deletions
@@ -1,8 +1,6 @@
import { PATH } from "~/const";
import token from "~/pages/api/auth/Token";
export default class SecurityClient {
static authOrigins = [PATH];
static #token = "";
contructor() {}
@@ -13,13 +11,12 @@ export default class SecurityClient {
static async fetchCall(resource, options) {
let req = new Request(resource, options);
const destOrigin = new URL(req.url).origin;
if (this.#token == "") {
this.setToken(await token());
}
if (this.#token && this.authOrigins.includes(destOrigin)) {
if (this.#token) {
req.headers.set("Authorization", "Bearer " + this.#token);
return fetch(req);
}