Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #474 from solocommand/idx-svc-set-token
Browse files Browse the repository at this point in the history
Add method to set token and re-init context client
  • Loading branch information
solocommand authored Nov 3, 2022
2 parents aa3a9a8 + b4a757c commit 22d236d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/marko-web-identity-x/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ class IdentityX {
} = {}) {
this.req = req;
this.res = res;
this.token = tokenCookie.getFrom(req);
this.config = config;
this.client = createClient({
req,
token: this.token,
appId: config.getAppId(),
config,
});
this.setToken(tokenCookie.getFrom(req));
}

/**
Expand Down Expand Up @@ -128,6 +122,22 @@ class IdentityX {
return data.addAppUserExternalId;
}

/**
*
* @param {*} param0
*/
setToken(token) {
this.token = token;

// Re-init the client if the token changed
this.client = createClient({
req: this.req,
token,
appId: this.config.getAppId(),
config: this.config,
});
}

async impersonateAppUser({ userId }) {
const apiToken = this.config.getApiToken();
if (!apiToken) throw new Error('Unable to add external ID: No API token has been configured.');
Expand All @@ -139,15 +149,7 @@ class IdentityX {
});
const { token } = data.impersonateAppUser;
tokenCookie.setTo(this.res, token.value);
this.token = token;

// Re-init the client because the token changed
this.client = createClient({
req: this.req,
token,
appId: this.config.getAppId(),
config: this.config,
});
this.setToken(token);
}

async logoutAppUser() {
Expand Down

0 comments on commit 22d236d

Please sign in to comment.