From 9c14fe811e3c35e5744585a2f77a59992bd90fcf Mon Sep 17 00:00:00 2001 From: Claudio Savino Date: Sun, 21 May 2023 15:13:55 +0200 Subject: [PATCH 1/2] fix: removeAccessToken throws error if storage not defined on handleError --- packages/authentication-client/src/core.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/authentication-client/src/core.ts b/packages/authentication-client/src/core.ts index 01c99c0da1..658195b1c2 100644 --- a/packages/authentication-client/src/core.ts +++ b/packages/authentication-client/src/core.ts @@ -152,7 +152,9 @@ export class AuthenticationClient { // For NotAuthenticated, PaymentError, Forbidden, NotFound, MethodNotAllowed, NotAcceptable // errors, remove the access token if (error.code > 400 && error.code < 408) { - const promise = this.removeAccessToken().then(() => this.reset()) + const promise = (this.storage as StorageWrapper).storage + ? this.removeAccessToken().then(() => this.reset()) + : Promise.resolve(); return type === 'logout' ? promise : promise.then(() => Promise.reject(error)) } From 7602875d2816f3efe7d377e3170d4766f29a13ba Mon Sep 17 00:00:00 2001 From: Claudio Savino Date: Mon, 22 May 2023 18:36:39 +0200 Subject: [PATCH 2/2] fix: removeItem throws error if storage undefined --- packages/authentication-client/src/core.ts | 4 +--- packages/authentication-client/src/storage.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/authentication-client/src/core.ts b/packages/authentication-client/src/core.ts index 658195b1c2..01c99c0da1 100644 --- a/packages/authentication-client/src/core.ts +++ b/packages/authentication-client/src/core.ts @@ -152,9 +152,7 @@ export class AuthenticationClient { // For NotAuthenticated, PaymentError, Forbidden, NotFound, MethodNotAllowed, NotAcceptable // errors, remove the access token if (error.code > 400 && error.code < 408) { - const promise = (this.storage as StorageWrapper).storage - ? this.removeAccessToken().then(() => this.reset()) - : Promise.resolve(); + const promise = this.removeAccessToken().then(() => this.reset()) return type === 'logout' ? promise : promise.then(() => Promise.reject(error)) } diff --git a/packages/authentication-client/src/storage.ts b/packages/authentication-client/src/storage.ts index 39e6817455..52ae5cbc3f 100644 --- a/packages/authentication-client/src/storage.ts +++ b/packages/authentication-client/src/storage.ts @@ -44,6 +44,6 @@ export class StorageWrapper implements Storage { } removeItem(key: string) { - return Promise.resolve(this.storage.removeItem(key)) + return Promise.resolve(this.storage?.removeItem(key)) } }