split signOut and clear token into two methods
This commit is contained in:
@@ -77,8 +77,8 @@ export class UmbAppElement extends UmbLitElement {
|
||||
async #setup() {
|
||||
if (this.serverUrl === undefined) throw new Error('No serverUrl provided');
|
||||
|
||||
/* All requests to the server requires the base URL to be set.
|
||||
We make sure it happens before we get the server status.
|
||||
/* All requests to the server requires the base URL to be set.
|
||||
We make sure it happens before we get the server status.
|
||||
TODO: find the right place to set this
|
||||
*/
|
||||
OpenAPI.BASE = this.serverUrl;
|
||||
@@ -93,7 +93,7 @@ export class UmbAppElement extends UmbLitElement {
|
||||
// If the runtime level is "install" we should clear any cached tokens
|
||||
// else we should try and set the auth status
|
||||
if (this.#serverConnection.getStatus() === RuntimeLevelModel.INSTALL) {
|
||||
await this.#authContext.signOut();
|
||||
await this.#authContext.clearTokenStorage();
|
||||
} else {
|
||||
await this.#setAuthStatus();
|
||||
}
|
||||
|
||||
@@ -223,6 +223,17 @@ export class UmbAuthFlow {
|
||||
return !!this.#accessTokenResponse && this.#accessTokenResponse.isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all cached token state
|
||||
*/
|
||||
async clearTokenStorage() {
|
||||
await this.#storageBackend.removeItem(TOKEN_RESPONSE_NAME);
|
||||
|
||||
// clear the internal state
|
||||
this.#accessTokenResponse = undefined;
|
||||
this.#refreshToken = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will sign the user out of the application.
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,11 @@ export interface IUmbAuthContext {
|
||||
*/
|
||||
getLatestToken(): Promise<string>;
|
||||
|
||||
/**
|
||||
* Clears the token storage.
|
||||
*/
|
||||
clearTokenStorage(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Signs the user out by removing any tokens from the browser.
|
||||
*/
|
||||
|
||||
@@ -65,6 +65,14 @@ export class UmbAuthContext extends UmbBaseController implements IUmbAuthContext
|
||||
return this.#authFlow.performWithFreshTokens();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the token storage.
|
||||
* @memberof UmbAuthContext
|
||||
*/
|
||||
clearTokenStorage() {
|
||||
return this.#authFlow.clearTokenStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs the user out by removing any tokens from the browser.
|
||||
* @return {*} {Promise<void>}
|
||||
|
||||
Reference in New Issue
Block a user