Redirect methode update & added env variable
This commit is contained in:
parent
55c30134ff
commit
89f7923e43
@ -23,6 +23,7 @@ import Iframe from "src/sdk/Iframe";
|
|||||||
|
|
||||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||||
import { ProgressInfo } from "src/common/Api/LeCoffreApi/sdk/ImportData";
|
import { ProgressInfo } from "src/common/Api/LeCoffreApi/sdk/ImportData";
|
||||||
|
import { FrontendVariables } from "@Front/Config/VariablesFront";
|
||||||
|
|
||||||
export default function LoginCallBack() {
|
export default function LoginCallBack() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -44,7 +45,7 @@ export default function LoginCallBack() {
|
|||||||
resolve(UserStore.instance.getUser());
|
resolve(UserStore.instance.getUser());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll for userInfo every 100ms
|
// Poll for userInfo every 100ms
|
||||||
const checkInterval = setInterval(() => {
|
const checkInterval = setInterval(() => {
|
||||||
if (UserStore.instance.getUser()) {
|
if (UserStore.instance.getUser()) {
|
||||||
@ -52,7 +53,7 @@ export default function LoginCallBack() {
|
|||||||
resolve(UserStore.instance.getUser());
|
resolve(UserStore.instance.getUser());
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
// Timeout after 60 seconds
|
// Timeout after 60 seconds
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
@ -65,14 +66,22 @@ export default function LoginCallBack() {
|
|||||||
async function getUser() {
|
async function getUser() {
|
||||||
UserStore.instance.disconnect();
|
UserStore.instance.disconnect();
|
||||||
|
|
||||||
// TODO: review
|
const variables = FrontendVariables.getInstance();
|
||||||
// HACK: If start with http://local.lecoffreio.4nkweb:3000/authorized-client
|
if (!variables?.ANK_BASE_REDIRECT_URI || !variables?.FRONT_APP_HOST) {
|
||||||
// Replace with http://localhost:3000/authorized-client
|
console.error("Redirect URIs not properly configured");
|
||||||
if (window.location.href.startsWith('http://local.4nkweb.com')) {
|
} else if (window.location.href.startsWith(`${variables.ANK_BASE_REDIRECT_URI}/authorized-client`)) {
|
||||||
window.location.href = window.location.href.replace('http://local.4nkweb.com:3000/authorized-client', 'http://localhost:3000/authorized-client');
|
const newUrl = window.location.href.replace(
|
||||||
return;
|
`${variables.ANK_BASE_REDIRECT_URI}/authorized-client`,
|
||||||
|
`${variables.FRONT_APP_HOST}/authorized-client`
|
||||||
|
);
|
||||||
|
history.replaceState(null, '', newUrl); // Change l'URL sans rechargement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// else if (window.location.href.startsWith(variables.ANK_BASE_REDIRECT_URI)) {
|
||||||
|
// window.location.href = window.location.href.replace(`${variables.ANK_BASE_REDIRECT_URI}/authorized-client`, `${variables.FRONT_APP_HOST}/authorized-client`);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
const code = router.query["code"];
|
const code = router.query["code"];
|
||||||
if (code) {
|
if (code) {
|
||||||
try {
|
try {
|
||||||
@ -83,15 +92,15 @@ export default function LoginCallBack() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user: any = await Auth.getInstance().idNotAuth(code as string);
|
const user: any = await Auth.getInstance().idNotAuth(code as string);
|
||||||
|
|
||||||
// Extract both user data and auth token from the response
|
// Extract both user data and auth token from the response
|
||||||
const { idNotUser, authToken } = user;
|
const { idNotUser, authToken } = user;
|
||||||
|
|
||||||
if (!authToken) {
|
if (!authToken) {
|
||||||
console.error('[LoginCallback] No authToken received from backend');
|
console.error('[LoginCallback] No authToken received from backend');
|
||||||
return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1");
|
return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the auth token for API authentication
|
// Store the auth token for API authentication
|
||||||
// TODO The authToken is just a uuid for now, it's very broken
|
// TODO The authToken is just a uuid for now, it's very broken
|
||||||
CookieService.getInstance().setCookie("leCoffreAccessToken", authToken);
|
CookieService.getInstance().setCookie("leCoffreAccessToken", authToken);
|
||||||
@ -109,7 +118,7 @@ export default function LoginCallBack() {
|
|||||||
CookieService.getInstance().setCookie("leCoffreUserInfo", JSON.stringify(userInfoResponse.data));
|
CookieService.getInstance().setCookie("leCoffreUserInfo", JSON.stringify(userInfoResponse.data));
|
||||||
setIsAuthModalOpen(true);
|
setIsAuthModalOpen(true);
|
||||||
console.log('[LoginCallback] authToken stored successfully');
|
console.log('[LoginCallback] authToken stored successfully');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.http_status === 401 && e.message === "Email not found") {
|
if (e.http_status === 401 && e.message === "Email not found") {
|
||||||
@ -217,7 +226,7 @@ export default function LoginCallBack() {
|
|||||||
// Office may not have a process too
|
// Office may not have a process too
|
||||||
let collaboratorProcess: { processId: string, processData: { [key: string]: any } } | null = null;
|
let collaboratorProcess: { processId: string, processData: { [key: string]: any } } | null = null;
|
||||||
let officeProcess: { processId: string, processData: { [key: string]: any } } | null = null;
|
let officeProcess: { processId: string, processData: { [key: string]: any } } | null = null;
|
||||||
|
|
||||||
// Initialize collaborator process
|
// Initialize collaborator process
|
||||||
try {
|
try {
|
||||||
// Wait for pairing ID to be available before proceeding
|
// Wait for pairing ID to be available before proceeding
|
||||||
@ -225,7 +234,7 @@ export default function LoginCallBack() {
|
|||||||
console.log('[LoginCallback] Pairing ID obtained:', pairingId);
|
console.log('[LoginCallback] Pairing ID obtained:', pairingId);
|
||||||
// Check if we are part of the right collaborator process
|
// Check if we are part of the right collaborator process
|
||||||
const myCollaboratorProcessesData = await MessageBus.getInstance().getProcessesDecoded((processId: string, values: { [key: string]: any }) => {
|
const myCollaboratorProcessesData = await MessageBus.getInstance().getProcessesDecoded((processId: string, values: { [key: string]: any }) => {
|
||||||
return values['utype'] === 'collaborator'
|
return values['utype'] === 'collaborator'
|
||||||
&& values['idNot'] === userInfo.idNot
|
&& values['idNot'] === userInfo.idNot
|
||||||
&& values['isDeleted'] === 'false';
|
&& values['isDeleted'] === 'false';
|
||||||
});
|
});
|
||||||
@ -261,7 +270,7 @@ export default function LoginCallBack() {
|
|||||||
console.log('[LoginCallback] Pairing ID obtained:', pairingId);
|
console.log('[LoginCallback] Pairing ID obtained:', pairingId);
|
||||||
// Now we need to check for office process
|
// Now we need to check for office process
|
||||||
const myOfficeProcessesData = await MessageBus.getInstance().getProcessesDecoded((processId: string, values: { [key: string]: any }) => {
|
const myOfficeProcessesData = await MessageBus.getInstance().getProcessesDecoded((processId: string, values: { [key: string]: any }) => {
|
||||||
return values['utype'] === 'office'
|
return values['utype'] === 'office'
|
||||||
&& values['idNot'] === userInfo.office.idNot
|
&& values['idNot'] === userInfo.office.idNot
|
||||||
&& values['isDeleted'] === 'false';
|
&& values['isDeleted'] === 'false';
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user