Skip to content

Commit

Permalink
Merge pull request #214 from ymaheshwari1/threshold/single-logout
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ravilodhi authored Sep 22, 2023
2 parents bb54768 + b714319 commit 2bf9d5a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 6 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 22 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'



Expand Down Expand Up @@ -96,10 +97,22 @@ const actions: ActionTree<UserState, RootState> = {
* 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()
Expand All @@ -116,6 +129,14 @@ const actions: ActionTree<UserState, RootState> = {

// 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;
},

/**
Expand Down
9 changes: 6 additions & 3 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2bf9d5a

Please sign in to comment.