diff --git a/src/front/Api/BaseApiService.ts b/src/front/Api/BaseApiService.ts index 6541d135..062b82cc 100644 --- a/src/front/Api/BaseApiService.ts +++ b/src/front/Api/BaseApiService.ts @@ -1,7 +1,5 @@ import { FrontendVariables } from "@Front/Config/VariablesFront"; import CookieService from "@Front/Services/CookieService/CookieService"; -import jwt_decode from "jwt-decode"; -import JwtService, { ICustomerJwtPayload, IUserJwtPayload } from "@Front/Services/JwtService/JwtService"; export enum ContentType { JSON = "application/json", @@ -21,6 +19,8 @@ export default abstract class BaseApiService { BaseApiService.baseUrl ??= this.variables.BACK_API_PROTOCOL + this.variables.BACK_API_HOST + + ':' + + this.variables.BACK_API_PORT + this.variables.BACK_API_ROOT_URL + this.variables.BACK_API_VERSION; } @@ -45,8 +45,7 @@ export default abstract class BaseApiService { return JSON.stringify(body); } - protected async getRequest(url: URL, token?: string, contentType?: ContentType, ref?: IRef, fileName?: string) { - await this.checkJwtToken(); + protected async getRequest(url: URL, contentType?: ContentType, ref?: IRef, fileName?: string) { const request = async () => await fetch(url, { method: "GET", @@ -55,8 +54,7 @@ export default abstract class BaseApiService { return this.sendRequest(request, ref, fileName); } - protected async postRequest(url: URL, body: { [key: string]: unknown } = {}, token?: string) { - //await this.checkJwtToken(); + protected async postRequest(url: URL, body: { [key: string]: unknown } = {}) { return this.sendRequest( async () => await fetch(url, { @@ -68,7 +66,6 @@ export default abstract class BaseApiService { } protected async postRequestFormData(url: URL, body: FormData) { - await this.checkJwtToken(); return this.sendRequest( async () => await fetch(url, { @@ -80,7 +77,6 @@ export default abstract class BaseApiService { } protected async putRequest(url: URL, body: { [key: string]: unknown } = {}, token?: string) { - await this.checkJwtToken(); const request = async () => await fetch(url, { method: "PUT", @@ -92,7 +88,6 @@ export default abstract class BaseApiService { } protected async patchRequest(url: URL, body: { [key: string]: unknown } = {}) { - await this.checkJwtToken(); const request = async () => await fetch(url, { method: "PATCH", @@ -104,7 +99,6 @@ export default abstract class BaseApiService { } protected async deleteRequest(url: URL, body: { [key: string]: unknown } = {}, token?: string) { - await this.checkJwtToken(); const request = async () => await fetch(url, { method: "DELETE", @@ -116,7 +110,6 @@ export default abstract class BaseApiService { } protected async putFormDataRequest(url: URL, body: FormData, token?: string) { - await this.checkJwtToken(); const request = async () => await fetch(url, { method: "PUT", @@ -133,41 +126,6 @@ export default abstract class BaseApiService { return this.processResponse(response, request, ref, fileName); } - private async checkJwtToken() { - const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken"); - if (!accessToken) return; - - const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload; - const customerDecodedToken = jwt_decode(accessToken) as ICustomerJwtPayload; - - if (!userDecodedToken && !customerDecodedToken) return; - - const now = Math.floor(Date.now() / 1000); - if (userDecodedToken.userId && userDecodedToken.exp < now) { - const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken"); - if (!refreshToken) { - return; - } - const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload; - if (decodedRefreshToken.exp < now) { - return; - } - await JwtService.getInstance().refreshToken(refreshToken); - } - if (customerDecodedToken.customerId && customerDecodedToken.exp < now) { - const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken"); - if (!refreshToken) { - return; - } - const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload; - if (decodedRefreshToken.exp < now) { - return; - } - await JwtService.getInstance().refreshToken(refreshToken); - } - return; - } - protected async processResponse(response: Response, request: () => Promise, ref?: IRef, fileName?: string): Promise { let responseContent: T; ref && (ref["response"] = response);