diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 9fe14465..7de75330 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -162,10 +162,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { } // in IE, sessionStorage does not always survive a redirect - if ( - typeof window !== 'undefined' && - typeof window['localStorage'] !== 'undefined' - ) { + if (this.checkLocalStorageAccessable()) { const ua = window?.navigator?.userAgent; const msie = ua?.includes('MSIE ') || ua?.includes('Trident'); @@ -177,6 +174,23 @@ export class OAuthService extends AuthConfig implements OnDestroy { this.setupRefreshTimer(); } + private checkLocalStorageAccessable(){ + if(typeof window === 'undefined') + return false; + + const test = 'test'; + try { + if(typeof window['localStorage'] === 'undefined') + return false; + + localStorage.setItem(test, test); + localStorage.removeItem(test); + return true; + } catch(e) { + return false; + } + } + /** * Use this method to configure the service * @param config the configuration