Skip to content

Commit

Permalink
Merge pull request #53 from ymaheshwari1/launchpad/single-logout
Browse files Browse the repository at this point in the history
Implemented: support for single logout
  • Loading branch information
ravilodhi authored Sep 13, 2023
2 parents a5ff97b + cac7d5b commit 8ef8c08
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"i18n:report": "vue-cli-service i18n:report --src \"./src/**/*.?(js|vue)\" --locales \"./src/locales/**/*.json\""
},
"dependencies": {
"@hotwax/oms-api": "^1.8.1",
"@hotwax/oms-api": "^1.9.0",
"@ionic/vue": "^6.0.2",
"@ionic/vue-router": "^6.0.2",
"core-js": "^3.8.3",
Expand Down
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export default defineComponent({
.play();
},
async unauthorized() {
this.authStore.logout()
// Mark the user as unauthorised, this will help in not making the logout api call in actions
this.authStore.logout({ isUserUnauthorised: true })
this.router.push("/login")
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { api, client, hasError, initialise, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'
import { api, client, hasError, logout, initialise, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'

export {
api,
client,
hasError,
logout,
initialise,
resetConfig,
updateInstanceUrl,
Expand Down
10 changes: 8 additions & 2 deletions src/store/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import { DateTime } from "luxon";
import { UserService } from '@/services/UserService';
import { hasError, updateInstanceUrl, updateToken } from '@/adapter';
import { hasError, logout, updateInstanceUrl, updateToken } from '@/adapter';
import { showToast } from '@/util';
import { translate } from '@/i18n'

Expand Down Expand Up @@ -86,7 +86,13 @@ export const useAuthStore = defineStore('authStore', {
return Promise.reject(new Error(error))
}
},
async logout() {
async logout(payload?: any) {
// 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();
}

// resetting the whole state except oms
// TODO Check why $patch failed to update current and use
this.current = {}
Expand Down
11 changes: 6 additions & 5 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export default defineComponent({
return
}
// logout from Launchpad if logged out from the app
if (this.$route.query?.isLoggedOut === 'true') {
// We will already mark the user as unuauthorised when log-out from the app
this.authStore.logout({ isUserUnauthorised: true })
}
// fetch login options only if OMS is there as API calls require OMS
if (this.authStore.getOMS) {
await this.fetchLoginOptions()
Expand All @@ -133,11 +139,6 @@ export default defineComponent({
this.showOmsInput = true
}
// logout from Launchpad if logged out from the app
if (this.$route.query?.isLoggedOut === 'true') {
this.authStore.logout()
}
// Update OMS input if found in query
if (this.$route.query?.oms) {
this.instanceUrl = this.$route.query.oms as string
Expand Down

0 comments on commit 8ef8c08

Please sign in to comment.