Skip to content

Commit

Permalink
Merge pull request #212 from ymaheshwari1/threshold/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 c25de98 + e5ad97c commit 1f2b522
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@casl/vue": "^2.2.0",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.1.0",
"@hotwax/dxp-components": "^1.3.4",
"@hotwax/oms-api": "^1.6.0",
"@hotwax/dxp-components": "1.5.3",
"@hotwax/oms-api": "^1.9.0",
"@ionic/core": "6.7.5",
"@ionic/vue": "6.7.5",
"@ionic/vue-router": "6.7.5",
Expand Down
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default defineComponent({
}
},
async unauthorized() {
this.store.dispatch("user/logout");
// Mark the user as unauthorised, this will help in not making the logout api call in actions
this.store.dispatch("user/logout", { isUserUnauthorised: true });
const redirectUrl = window.location.origin + '/login';
window.location.href = `${process.env.VUE_APP_LOGIN_URL}?redirectUrl=${redirectUrl}`;
}
Expand Down
4 changes: 3 additions & 1 deletion src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { api, client, init, initialise, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'
import { api, client, getConfig, init, initialise, logout, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'

export {
api,
client,
getConfig,
init,
initialise,
logout,
resetConfig,
updateInstanceUrl,
updateToken
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import permissionRules from '@/authorization/Rules';
import permissionActions from '@/authorization/Actions';
import { dxpComponents } from '@hotwax/dxp-components'
import { login, logout, loader } from './user-utils';
import { getConfig, initialise } from '@/adapter'


const app = createApp(App)
Expand All @@ -56,7 +57,9 @@ const app = createApp(App)
login,
logout,
loader,
appLoginUrl: process.env.VUE_APP_LOGIN_URL as string
appLoginUrl: process.env.VUE_APP_LOGIN_URL as string,
getConfig: getConfig,
initialise: initialise
});

// Filters are removed in Vue 3 and global filter introduced https://v3.vuejs.org/guide/migration/filters.html#global-filters
Expand Down
10 changes: 8 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
resetPermissions,
setPermissions
} from '@/authorization'
import { updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import { logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import { useAuthStore } from '@hotwax/dxp-components'


Expand Down Expand Up @@ -95,7 +95,13 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Logout user
*/
async logout ({ commit }) {
async logout ({ commit }, payload) {
// 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();
}

const authStore = useAuthStore()

// TODO add any other tasks if need
Expand Down
2 changes: 1 addition & 1 deletion src/user-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { loadingController } from '@ionic/vue'

const login = async (payload: any) => store.dispatch('user/login', payload);

const logout = async () => store.dispatch('user/logout');
const logout = async (payload: any) => store.dispatch('user/logout', payload);

const loader = {
value: null as any,
Expand Down

0 comments on commit 1f2b522

Please sign in to comment.