Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: support to redefine the events passed from the app after clearing the user state #150

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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