From 6b49bbbe577874420b009e534c97a9d92c4564b9 Mon Sep 17 00:00:00 2001 From: Mohamed Maoulainine Maoulainine Date: Sat, 10 May 2025 23:35:30 +0200 Subject: [PATCH] fix: handlers weren't used properly in the unauth code --- .../src/components/LoginComponent.vue | 9 +++----- .../src/services/Apis/Unauth.ts | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/front/MyINPulse-front/src/components/LoginComponent.vue b/front/MyINPulse-front/src/components/LoginComponent.vue index 5d8b29a..48d74bf 100644 --- a/front/MyINPulse-front/src/components/LoginComponent.vue +++ b/front/MyINPulse-front/src/components/LoginComponent.vue @@ -25,19 +25,16 @@ onMounted(() => { router.push("/admin"); return; } - + /* if (roles.includes("MyINPulse-entrepreneur")) { router.push("/canvas"); return; - } + }*/ checkPending( (response) => { const isValidated = response.data === true; - if ( - isValidated && - roles.includes("MyINPulse-entrepreneur") - ) { + if (isValidated && roles.includes("MyINPulse-entrepreneur")) { router.push("/canvas"); //router.push("/JorCproject"); } else { diff --git a/front/MyINPulse-front/src/services/Apis/Unauth.ts b/front/MyINPulse-front/src/services/Apis/Unauth.ts index 90dc2f7..7c8915a 100644 --- a/front/MyINPulse-front/src/services/Apis/Unauth.ts +++ b/front/MyINPulse-front/src/services/Apis/Unauth.ts @@ -74,15 +74,27 @@ function getAllEntrepreneurs( }); } -function checkPending(): Promise { - return axiosInstance +function checkPending( + onSuccessHandler?: (response: AxiosResponse) => void, + onErrorHandler?: (error: AxiosError) => void +): void { + axiosInstance .get("/unauth/check-if-not-pending") - .then((response) => response.data) + .then((response) => { + if (onSuccessHandler) { + onSuccessHandler(response); + } else { + defaultApiSuccessHandler(response); + } + }) .catch((error: AxiosError) => { - throw error; + if (onErrorHandler) { + onErrorHandler(error); + } else { + defaultApiErrorHandler(error); + } }); } - export { finalizeAccount, getAllEntrepreneurs,