accessToken in header
This commit is contained in:
parent
de851859e6
commit
ec60a5bfd9
@ -1,4 +1,5 @@
|
|||||||
import { FrontendVariables } from "@Front/Config/VariablesFront";
|
import { FrontendVariables } from "@Front/Config/VariablesFront";
|
||||||
|
import CookieService from "@Front/Services/CookieService/CookieService";
|
||||||
|
|
||||||
export enum ContentType {
|
export enum ContentType {
|
||||||
JSON = "application/json",
|
JSON = "application/json",
|
||||||
@ -20,13 +21,15 @@ export default abstract class BaseApiService {
|
|||||||
return BaseApiService.baseUrl;
|
return BaseApiService.baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected buildHeaders(contentType: ContentType, token?: string) {
|
protected buildHeaders(contentType: ContentType) {
|
||||||
|
const token = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||||
|
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
|
|
||||||
if (contentType === ContentType.JSON) {
|
if (contentType === ContentType.JSON) {
|
||||||
headers.set("Content-Type", contentType);
|
headers.set("Content-Type", contentType);
|
||||||
}
|
}
|
||||||
if (token) headers.set("Authorization", `Bearer ${token}`);
|
headers.set("Authorization", `Bearer ${token}`);
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +41,7 @@ export default abstract class BaseApiService {
|
|||||||
const request = async () =>
|
const request = async () =>
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: this.buildHeaders(ContentType.JSON, token),
|
headers: this.buildHeaders(ContentType.JSON),
|
||||||
});
|
});
|
||||||
return this.sendRequest<T>(request);
|
return this.sendRequest<T>(request);
|
||||||
}
|
}
|
||||||
@ -48,7 +51,7 @@ export default abstract class BaseApiService {
|
|||||||
async () =>
|
async () =>
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.buildHeaders(ContentType.JSON, token),
|
headers: this.buildHeaders(ContentType.JSON),
|
||||||
body: this.buildBody(body),
|
body: this.buildBody(body),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -69,7 +72,7 @@ export default abstract class BaseApiService {
|
|||||||
const request = async () =>
|
const request = async () =>
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.buildHeaders(ContentType.JSON, token),
|
headers: this.buildHeaders(ContentType.JSON),
|
||||||
body: this.buildBody(body),
|
body: this.buildBody(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,7 +94,7 @@ export default abstract class BaseApiService {
|
|||||||
const request = async () =>
|
const request = async () =>
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.buildHeaders(ContentType.JSON, token),
|
headers: this.buildHeaders(ContentType.JSON),
|
||||||
body: this.buildBody(body),
|
body: this.buildBody(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -102,7 +105,7 @@ export default abstract class BaseApiService {
|
|||||||
const request = async () =>
|
const request = async () =>
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.buildHeaders(ContentType.FORM_DATA, token),
|
headers: this.buildHeaders(ContentType.FORM_DATA),
|
||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoub
|
|||||||
// import { FrontendVariables } from "@Front/Config/VariablesFront";
|
// import { FrontendVariables } from "@Front/Config/VariablesFront";
|
||||||
import idNoteLogo from "@Assets/Icons/id-note-logo.svg";
|
import idNoteLogo from "@Assets/Icons/id-note-logo.svg";
|
||||||
import UserStore from "@Front/Stores/UserStore";
|
import UserStore from "@Front/Stores/UserStore";
|
||||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
|
||||||
|
|
||||||
export default class LoginClass extends BasePage {
|
export default class LoginClass extends BasePage {
|
||||||
public override render(): JSX.Element {
|
public override render(): JSX.Element {
|
||||||
@ -36,7 +35,7 @@ export default class LoginClass extends BasePage {
|
|||||||
// const variables = FrontendVariables.getInstance();
|
// const variables = FrontendVariables.getInstance();
|
||||||
// const baseFronturl = variables.BACK_API_PROTOCOL + variables.FRONT_APP_HOST;
|
// const baseFronturl = variables.BACK_API_PROTOCOL + variables.FRONT_APP_HOST;
|
||||||
|
|
||||||
await UserStore.instance.connect("A1QAuhlImn");
|
await UserStore.instance.connect("U5eUoGpRu4");
|
||||||
// await JwtService.getInstance().checkJwt();
|
// await JwtService.getInstance().checkJwt();
|
||||||
// window.location.assign("http://localhost:3000" + "/folders");
|
// window.location.assign("http://localhost:3000" + "/folders");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user