From f915d87b08fd09c26dda1147ea7b8e202d26352c Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 22 Sep 2023 11:39:22 +0530 Subject: [PATCH 1/3] Removed: duplicate entry from env example --- .env.example | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.example b/.env.example index bb39a492..495de819 100644 --- a/.env.example +++ b/.env.example @@ -9,5 +9,4 @@ VUE_APP_PERMISSION_ID= VUE_APP_ALIAS={} VUE_APP_DEFAULT_ALIAS="" VUE_APP_DEFAULT_LOG_LEVEL="error" -VUE_APP_DEFAULT_LOG_LEVEL="error" VUE_APP_LOGIN_URL="http://launchpad.hotwax.io/login" From 5f5ef01b9c4937f9bd20a2b5a6edd7c5b5654590 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 22 Sep 2023 11:56:16 +0530 Subject: [PATCH 2/3] Improved: code to redirect the user to SSO screen when enabled otherwise redirect to launchpad on logout, and added support to loader for custom message in case of logout --- src/App.vue | 9 ++++++--- src/locales/en.json | 1 + src/store/modules/user/actions.ts | 23 ++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index 71cda030..a7e43f2f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -42,13 +42,16 @@ export default defineComponent({ }) }, methods: { - async presentLoader() { + async presentLoader(options = { message: '', backdropDismiss: true }) { + // When having a custom message remove already existing loader + if(options.message && this.loader) this.dismissLoader(); + if (!this.loader) { this.loader = await loadingController .create({ - message: this.$t("Click the backdrop to dismiss."), + message: options.message ? this.$t(options.message) : this.$t("Click the backdrop to dismiss."), translucent: true, - backdropDismiss: true + backdropDismiss: options.backdropDismiss }); } this.loader.present(); diff --git a/src/locales/en.json b/src/locales/en.json index 9815b0d7..e713629a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -55,6 +55,7 @@ "Loading": "Loading", "Login": "Login", "Logging in": "Logging in", + "Logging out": "Logging out", "Logout": "Logout", "Make sure you have saved your changes. All unsaved changes to this rule will be lost.": "Make sure you have saved your changes. All unsaved changes to this rule will be lost.", "Menu": "Menu", diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index dcbf36b9..7620395f 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -15,6 +15,7 @@ import { } from '@/authorization' import { logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter' import { useAuthStore } from '@hotwax/dxp-components' +import emitter from '@/event-bus' @@ -96,10 +97,22 @@ const actions: ActionTree = { * Logout user */ async logout ({ commit }, payload) { + // store the url on which we need to redirect the user after logout api completes in case of SSO enabled + let redirectionUrl = '' + + emitter.emit('presentLoader', { message: 'Logging out', backdropDismiss: false }) + // Calling the logout api to flag the user as logged out, only when user is authorised // if the user is already unauthorised then not calling the logout api as it returns 401 again that results in a loop, thus there is no need to call logout api if the user is unauthorised if(!payload?.isUserUnauthorised) { - await logout(); + let resp = await logout(); + + // Added logic to remove the `//` from the resp as in case of get request we are having the extra characters and in case of post we are having 403 + resp = JSON.parse(resp.startsWith('//') ? resp.replace('//', '') : resp) + + if(resp.logoutAuthType == 'SAML2SSO') { + redirectionUrl = resp.logoutUrl + } } const authStore = useAuthStore() @@ -116,6 +129,14 @@ const actions: ActionTree = { // reset plugin state on logout authStore.$reset() + + // If we get any url in logout api resp then we will redirect the user to the url + if(redirectionUrl) { + window.location.href = redirectionUrl + } + + emitter.emit('dismissLoader') + return redirectionUrl; }, /** From b7143199c0e5c3214eca6bcde5724f4f8d81a40f Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 22 Sep 2023 12:02:57 +0530 Subject: [PATCH 3/3] Updated: settings page to support redirection --- src/views/Settings.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/views/Settings.vue b/src/views/Settings.vue index bfb2582d..f5d6c2ae 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -170,9 +170,12 @@ export default defineComponent({ return timeZoneModal.present(); }, logout () { - this.store.dispatch('user/logout').then(() => { - const redirectUrl = window.location.origin + '/login' - window.location.href = `${process.env.VUE_APP_LOGIN_URL}?isLoggedOut=true&redirectUrl=${redirectUrl}` + this.store.dispatch('user/logout', { isUserUnauthorised: false }).then((redirectionUrl) => { + // if not having redirection url then redirect the user to launchpad + if(!redirectionUrl) { + const redirectUrl = window.location.origin + '/login' + window.location.href = `${process.env.VUE_APP_LOGIN_URL}?isLoggedOut=true&redirectUrl=${redirectUrl}` + } }) }, goToLaunchpad() {