diff --git a/package-lock.json b/package-lock.json index 5e236d71..d71c8643 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,8 +15,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", @@ -2204,9 +2204,9 @@ "integrity": "sha512-yokhlpG+eUEao19vaUtCOC5YwcYTb5sf5joGVH17mbb5B1hM4G+P4ZiGiFw2AMmZBKgu94DtHwSyjtdsf4bHug==" }, "node_modules/@hotwax/dxp-components": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/@hotwax/dxp-components/-/dxp-components-1.3.4.tgz", - "integrity": "sha512-uw0dmxm19lzsgcLWZ2fQBAZem0d7TkxGR0iSq1c7Bj1mkAJZXH5JbP12w0lYhtes7Q1MjhHPlWljCh6624E9XA==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@hotwax/dxp-components/-/dxp-components-1.5.3.tgz", + "integrity": "sha512-6u9CpzkYrgQt1tfMeXRgpXnh1hHYoagagDByX/8nfZ+VziKtSY70bfAves3AipluL3MdJq9WEpOzG0r0a/VA6g==", "dependencies": { "@hotwax/oms-api": "^1.8.1", "luxon": "^3.3.0", @@ -2224,9 +2224,9 @@ } }, "node_modules/@hotwax/oms-api": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-1.8.1.tgz", - "integrity": "sha512-pVceiuaOSkRZM3i87+TCEu6uBMDG01JGTG92mCpDUXWmA6nd0BL7QiK1Qr8a9lDTib0M24RVBDCGc/cX6nlxgg==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-1.9.0.tgz", + "integrity": "sha512-1PcS95vP8PzzlBRwHQRk99eJT0xStBSmNdpdoATRUSlLamxmHZ8RAwAwY3usph5gNy7Z+WzAxl9fJXX9VgWP9g==", "dependencies": { "@types/node-json-transform": "^1.0.0", "axios": "^0.21.1", @@ -34860,9 +34860,9 @@ "integrity": "sha512-yokhlpG+eUEao19vaUtCOC5YwcYTb5sf5joGVH17mbb5B1hM4G+P4ZiGiFw2AMmZBKgu94DtHwSyjtdsf4bHug==" }, "@hotwax/dxp-components": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/@hotwax/dxp-components/-/dxp-components-1.3.4.tgz", - "integrity": "sha512-uw0dmxm19lzsgcLWZ2fQBAZem0d7TkxGR0iSq1c7Bj1mkAJZXH5JbP12w0lYhtes7Q1MjhHPlWljCh6624E9XA==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@hotwax/dxp-components/-/dxp-components-1.5.3.tgz", + "integrity": "sha512-6u9CpzkYrgQt1tfMeXRgpXnh1hHYoagagDByX/8nfZ+VziKtSY70bfAves3AipluL3MdJq9WEpOzG0r0a/VA6g==", "requires": { "@hotwax/oms-api": "^1.8.1", "luxon": "^3.3.0", @@ -34879,9 +34879,9 @@ } }, "@hotwax/oms-api": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-1.8.1.tgz", - "integrity": "sha512-pVceiuaOSkRZM3i87+TCEu6uBMDG01JGTG92mCpDUXWmA6nd0BL7QiK1Qr8a9lDTib0M24RVBDCGc/cX6nlxgg==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-1.9.0.tgz", + "integrity": "sha512-1PcS95vP8PzzlBRwHQRk99eJT0xStBSmNdpdoATRUSlLamxmHZ8RAwAwY3usph5gNy7Z+WzAxl9fJXX9VgWP9g==", "requires": { "@types/node-json-transform": "^1.0.0", "axios": "^0.21.1", diff --git a/package.json b/package.json index 56def058..325739cb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/App.vue b/src/App.vue index 2322240e..71cda030 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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}`; } diff --git a/src/adapter/index.ts b/src/adapter/index.ts index 2e2381d5..23716e29 100644 --- a/src/adapter/index.ts +++ b/src/adapter/index.ts @@ -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 diff --git a/src/main.ts b/src/main.ts index 030b2b99..7802a487 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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) @@ -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 diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 40c5f87f..dcbf36b9 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -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' @@ -95,7 +95,13 @@ const actions: ActionTree = { /** * 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 diff --git a/src/user-utils/index.ts b/src/user-utils/index.ts index faf98e48..44c37aba 100644 --- a/src/user-utils/index.ts +++ b/src/user-utils/index.ts @@ -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,