From d7f5107ef76297b4ca6db580afc5e2b372f5ee4d Mon Sep 17 00:00:00 2001 From: David Luecke Date: Wed, 9 Oct 2019 18:59:15 -0700 Subject: [PATCH] fix: Improve authentication client default storage initialization (#1613) --- packages/authentication-client/src/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/authentication-client/src/index.ts b/packages/authentication-client/src/index.ts index 1f47ba6ef8..d2f7d49354 100644 --- a/packages/authentication-client/src/index.ts +++ b/packages/authentication-client/src/index.ts @@ -15,12 +15,19 @@ declare module '@feathersjs/feathers' { } } +export const getDefaultStorage = () => { + try { + return new StorageWrapper(window.localStorage); + } catch (error) {} + + return new MemoryStorage(); +}; + export { AuthenticationClient, AuthenticationClientOptions, Storage, MemoryStorage, hooks }; export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient; -export const defaultStorage: Storage = typeof window !== 'undefined' ? - new StorageWrapper(window.localStorage) : new MemoryStorage(); +export const defaultStorage: Storage = getDefaultStorage(); export const defaults: AuthenticationClientOptions = { header: 'Authorization',