add host variables depending on env

This commit is contained in:
OxSaitama 2023-04-13 11:07:06 +02:00
parent 395527cb1e
commit 139cbbf4f6
2 changed files with 72 additions and 21 deletions

View File

@ -1,5 +1,6 @@
import { Service } from "typedi"; import { Service } from "typedi";
import BaseApiService from "@Front/Api/BaseApiService"; import BaseApiService from "@Front/Api/BaseApiService";
import { FrontendVariables } from "@Front/Config/VariablesFront";
@Service() @Service()
export default class Auth extends BaseApiService { export default class Auth extends BaseApiService {
@ -25,15 +26,18 @@ export default class Auth extends BaseApiService {
} }
} }
public async getIdnotJwt(autorizationCode: string | string[]) { public async getIdnotJwt(autorizationCode: string | string[]): Promise<any> {
const baseBackUrl = FrontendVariables.getInstance().BACK_API_PROTOCOL +
FrontendVariables.getInstance().BACK_API_HOST +
(FrontendVariables.getInstance().BACK_API_PORT ? ":" + FrontendVariables.getInstance().BACK_API_PORT : "");
const url = new URL( const url = new URL(
`http://127.0.0.1:3001/api/v1/idnot-user/${autorizationCode}` `${baseBackUrl}/api/v1/idnot-user/${autorizationCode}`
); );
try { try {
await this.postRequest<any>(url); return await this.postRequest<any>(url);
} catch (err) { } catch (err) {
this.onError(err); this.onError(err);
//return Promise.reject(err); return Promise.reject(err);
} }
} }
} }

View File

@ -1,23 +1,43 @@
// import classes from "./classes.module.scss"; // import classes from "./classes.module.scss";
// import LandingImage from "../Login/landing-connect.png"; // import LandingImage from "../Login/landing-connect.png";
// import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; // import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage";
// import Image from "next/image";
// import CoffreIcon from "@Assets/Icons/coffre.svg";
// import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
// import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
//import React, { useEffect, useState } from "react";
import React from "react"; import React from "react";
//import Loader from "@Front/Components/DesignSystem/Loader"; //import Loader from "@Front/Components/DesignSystem/Loader";
import Auth from "@Front/Api/Auth/IdNot"; import Auth from "@Front/Api/Auth/IdNot";
import Folder from "../Folder"; import Folder from "../Folder";
import LoginClass from "../Login";
type IPropsClass = {}; type IPropsClass = {};
//type IStateClass = {}; // type IStateClass = {};
// class LoginCallBackClass extends React.Component<IPropsClass, IStateClass> { // class LoginCallBackClass extends React.Component<IPropsClass, IStateClass> {
// public override render(): JSX.Element { // public override render(): JSX.Element {
// return ( // return (
// <DefaultDoubleSidePage title={"Login"} image={LandingImage}> // <DefaultDoubleSidePage title={"Login"} image={LandingImage}>
// <div className={classes["root"]}> // <div className={classes["root"]}>
// <Image alt="coffre" src={CoffreIcon} />
// <Typography typo={ITypo.H1}>
// <div className={classes["title"]}>
// Connexion espace professionnel
// </div>
// </Typography>
// <Loader /> // <Loader />
// <Typography typo={ITypo.P_18}>
// <div className={classes["forget-password"]}>
// Vous narrivez pas à vous connecter ?
// </div>
// </Typography>
// <Button variant={EButtonVariant.LINE}>
// Contacter ladministrateur
// </Button>
// </div> // </div>
// </DefaultDoubleSidePage> // </DefaultDoubleSidePage>
// ); // );
@ -25,6 +45,32 @@ type IPropsClass = {};
// } // }
// TODO: Refacto with functionnal component container of classcomponent // TODO: Refacto with functionnal component container of classcomponent
// export default function LoginCallBack(props: IPropsClass) {
// const [user, setUser] = useState(null);
// const [isLoading, setIsLoading] = useState(false);
// const router = useRouter();
// const { code } = router.query;
// if (code) {
// useEffect(() => {
// const getIdNotJwt = async () => {
// setIsLoading(true);
// try {
// const authService = Auth.getInstance();
// const fetchedUser = await authService.getIdnotJwt(code);
// setUser(fetchedUser);
// } catch (error) {
// console.error(error);
// // Router.push('/login');
// }
// };
// getIdNotJwt();
// }, []);
// if (isLoading) return <LoginCallBackClass {... props}/>
// return <Folder {...props} />;
// }
// return <LoginClass {...props}/>
// }
export default function LoginCallBack(props: IPropsClass) { export default function LoginCallBack(props: IPropsClass) {
const router = useRouter(); const router = useRouter();
const { code } = router.query; const { code } = router.query;
@ -39,6 +85,7 @@ export default function LoginCallBack(props: IPropsClass) {
} }
}; };
getIdNotJwt(); getIdNotJwt();
}
return <Folder {...props} />; return <Folder {...props} />;
} }
return <LoginClass {...props}/>
}