Skip to content

Commit

Permalink
Merge pull request hotwax#150 from ymaheshwari1/dxp-component/single-…
Browse files Browse the repository at this point in the history
…logout

Improved: support to redefine the events passed from the app after clearing the user state
  • Loading branch information
ravilodhi authored Sep 12, 2023
2 parents c32908a + ddb66b2 commit 45eaaa0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/Login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent } from "vue"
import { loginContext as context, useAuthStore, appContext } from "../index"
import { loginContext as context, useAuthStore, appContext, loginContext } from "../index"
import { DateTime } from "luxon"

export default defineComponent({
Expand Down Expand Up @@ -33,8 +33,15 @@ export default defineComponent({
},
methods: {
async handleUserFlow(token: string, oms: string, expirationTime: string) {
// logout to clear current user state
await context.logout()

// fetch the current config for the user
const appConfig = loginContext.getConfig()

// logout to clear current user state, don't mark the user as logout as we just want to clear the user data
await context.logout({ isUserUnauthorised: true })

// reset the config that we got from the oms-api, as on logout we clear the config of oms-api
await context.initialise(appConfig)

// checking if token from launchpad has expired and redirecting there only
if (+expirationTime < DateTime.now().toMillis()) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export let dxpComponents = {
shopifyImgContext.defaultImgUrl = options.defaultImgUrl
productIdentificationContext.getProductIdentificationPref = options.getProductIdentificationPref
productIdentificationContext.setProductIdentificationPref = options.setProductIdentificationPref
loginContext.getConfig = options.getConfig
loginContext.initialise = options.initialise
}
}

Expand Down

0 comments on commit 45eaaa0

Please sign in to comment.