From 074e33329d67b58e6edc72f4b2d6ee23a3057a70 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Wed, 10 May 2023 17:11:04 +0200 Subject: [PATCH 1/2] fix login callback url --- src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts | 2 +- src/front/Components/Layouts/Login/index.tsx | 2 +- src/front/Config/VariablesFront.ts | 2 -- src/pages/_app.tsx | 4 ---- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts index 63cc47ed..8092167b 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts @@ -1,6 +1,6 @@ import { File } from "le-coffre-resources/dist/SuperAdmin"; import Container, { Service } from "typedi"; - +import "reflect-metadata"; import BaseSuperAdmin from "../BaseSuperAdmin"; import CryptoService from "@Front/Services/CryptoService/CryptoService"; diff --git a/src/front/Components/Layouts/Login/index.tsx b/src/front/Components/Layouts/Login/index.tsx index 196dd836..8a2480f6 100644 --- a/src/front/Components/Layouts/Login/index.tsx +++ b/src/front/Components/Layouts/Login/index.tsx @@ -30,7 +30,7 @@ export default class LoginClass extends BasePage { private redirectUserOnConnection() { const variables = FrontendVariables.getInstance(); const baseFronturl = - variables.BACK_API_PROTOCOL + variables.FRONT_APP_HOST + (variables.FRONT_APP_PORT ? ":" + variables.FRONT_APP_PORT : ""); + variables.BACK_API_PROTOCOL + variables.FRONT_APP_HOST; const authorizeEndPoint = variables.IDNOT_AUTHORIZE_ENDPOINT; const clientId = variables.IDNOT_CLIENT_ID; const url = `${authorizeEndPoint}?client_id=${clientId}&redirect_uri=${baseFronturl}/authorized-client&scope=openid,profile,offline_access&response_type=code`; diff --git a/src/front/Config/VariablesFront.ts b/src/front/Config/VariablesFront.ts index dd823f32..20422e9b 100644 --- a/src/front/Config/VariablesFront.ts +++ b/src/front/Config/VariablesFront.ts @@ -11,8 +11,6 @@ export class FrontendVariables { public FRONT_APP_HOST!: string; - public FRONT_APP_PORT!: string; - public IDNOT_AUTHORIZE_ENDPOINT!: string; public IDNOT_CLIENT_ID!: string; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index be5cf63c..a19fc74a 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -17,7 +17,6 @@ type AppPropsWithLayout = AppProps & { backApiRootUrl: string; backApiVersion: string; frontAppHost: string; - frontAppPort: string; idNotAuthorizeEndpoint: string; idNotClientId: string; }; @@ -30,7 +29,6 @@ const MyApp = (({ backApiRootUrl, backApiVersion, frontAppHost, - frontAppPort, idNotAuthorizeEndpoint, idNotClientId, }: AppPropsWithLayout) => { @@ -41,7 +39,6 @@ const MyApp = (({ FrontendVariables.getInstance().BACK_API_ROOT_URL = backApiRootUrl; FrontendVariables.getInstance().BACK_API_VERSION = backApiVersion; FrontendVariables.getInstance().FRONT_APP_HOST = frontAppHost; - FrontendVariables.getInstance().FRONT_APP_PORT = frontAppPort; FrontendVariables.getInstance().IDNOT_AUTHORIZE_ENDPOINT = idNotAuthorizeEndpoint; FrontendVariables.getInstance().IDNOT_CLIENT_ID = idNotClientId; @@ -55,7 +52,6 @@ MyApp.getInitialProps = async () => { backApiRootUrl: process.env["BACK_API_ROOT_URL"], backApiVersion: process.env["BACK_API_VERSION"], frontAppHost: process.env["FRONT_APP_HOST"], - frontAppPort: process.env["FRONT_APP_PORT"], idNotAuthorizeEndpoint: process.env["IDNOT_AUTHORIZE_ENDPOINT"], idNotClientId: process.env["IDNOT_CLIENT_ID"], }; From ed436facbfb9b223326d1041a28d8c4e655c3a21 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Tue, 11 Jul 2023 14:44:32 +0200 Subject: [PATCH 2/2] add office uid from cookies --- .../Layouts/Folder/CreateFolder/index.tsx | 15 ++++++++------- src/front/Services/JwtService/JwtService.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx index 5f26ce66..caddbd58 100644 --- a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx @@ -21,6 +21,7 @@ import { ActionMeta, MultiValue } from "react-select"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; +import JwtService from "@Front/Services/JwtService/JwtService"; type IFormValues = { folder_number: string; @@ -233,16 +234,12 @@ class CreateFolderClass extends BasePage { [key: string]: any; }, ) { + const officeId = (JwtService.getInstance().decodeJwt())?.office_Id; + console.log('form initializdd'); const selectedDeedTypeUid: DeedType | undefined = this.state.deedTypes.find( (deedType) => deedType.uid === this.state.formValues.act_typ?.value, ); - /** - * MOCK DATA - */ - const usersMock = await Users.getInstance().get({ include: { office_membership: true } }); - const userMock = usersMock[0]; - let stakeholders = this.state.collaborators; if (this.state.folder_access === "select_collaborators") { stakeholders = this.state.collaborators.filter((collaborator) => { @@ -261,23 +258,27 @@ class CreateFolderClass extends BasePage { }), }), office: Office.hydrate({ - uid: userMock?.office_membership?.uid, + uid: officeId, }), customers: [], stakeholders }); + console.log('form'); + try { await officeFolderForm.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false }); } catch (validationErrors) { this.setState({ validationError: validationErrors as ValidationError[], }); + console.log('validation errros'); return; } try { const newOfficeFolder = await Folders.getInstance().post(officeFolderForm); + console.log('new office folder: ',newOfficeFolder) if (!newOfficeFolder) return; this.props.router.push(`/folders/${newOfficeFolder.uid}`); } catch (backError: any) { diff --git a/src/front/Services/JwtService/JwtService.ts b/src/front/Services/JwtService/JwtService.ts index 5e1fd2b6..66db5c7c 100644 --- a/src/front/Services/JwtService/JwtService.ts +++ b/src/front/Services/JwtService/JwtService.ts @@ -26,15 +26,19 @@ export default class JwtService { return (this.instance ??= new this()); } + public decodeJwt(): IUserJwtPayload | undefined { + const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken"); + if (!accessToken) return; + return jwt_decode(accessToken); + } + /** * @description : set a cookie with a name and a value that expire in 7 days * @throws {Error} If the name or the value is empty */ public async checkJwt() { - const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken"); - - if (!accessToken) return; - const decodedToken: IUserJwtPayload = jwt_decode(accessToken); + const decodedToken = this.decodeJwt(); + if(!decodedToken) return; const now = Math.floor(Date.now() / 1000);