From f710bce5fef456167bb6ef609f56b79422618cfb Mon Sep 17 00:00:00 2001 From: Jon <24399271+Jon-Alonso@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:11:02 +1000 Subject: [PATCH] fix: Prevent accessing the global window object when instantiating Passport (#888) --- packages/passport/sdk/src/authManager.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/passport/sdk/src/authManager.ts b/packages/passport/sdk/src/authManager.ts index 28b023917e..b9ba76b51c 100644 --- a/packages/passport/sdk/src/authManager.ts +++ b/packages/passport/sdk/src/authManager.ts @@ -1,4 +1,5 @@ import { + InMemoryWebStorage, User as OidcUser, UserManager, UserManagerSettings, @@ -31,6 +32,9 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }: PassportConfiguration): UserManagerSettings => { + const store = typeof window !== 'undefined' ? window.localStorage : new InMemoryWebStorage(); + const userStore = new WebStorageStateStore({ store }); + const baseConfiguration: UserManagerSettings = { authority: authenticationDomain, redirect_uri: oidcConfiguration.redirectUri, @@ -48,7 +52,7 @@ const getAuthConfiguration = ({ mergeClaims: true, loadUserInfo: true, scope: oidcConfiguration.scope, - userStore: new WebStorageStateStore({ store: window.localStorage }), + userStore, }; if (oidcConfiguration.audience) {