Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageType undefined outside the interceptor? #66

Open
explody opened this issue Oct 31, 2023 · 1 comment
Open

StorageType undefined outside the interceptor? #66

explody opened this issue Oct 31, 2023 · 1 comment

Comments

@explody
Copy link

explody commented Oct 31, 2023

I'm a back-end coder, so go easy on me here, as this may be outright pilot error.

Setting up and using authTokenInterceptor looks to be working just fine, thanks for that - but, when trying to follow the examples in the README, to call e.g. setAuthTokens, isLoggedIn, etc outside the context of the interceptor, it seems like StorageProxy.Storage is just returning null, so those calls simply do nothing.

What am I missing here? If one calls setAuthTokens such as in the Login/Logout example, where is the storage actually being set?

I'm happy to give more detail or code snips, etc, as needed.

@explody
Copy link
Author

explody commented Oct 31, 2023

So, this feels awfully hacky but everything was solved in my case by simply having StorageProxt.Storage default to localStorage rather than null. What should be the right way of handling this?

StorageProxy.ts

import { BrowserStorageService } from './BrowserStorageService'
import { type StorageType } from './StorageType'

type StorageProxyType = {
  Storage: StorageType | null
}

export const StorageProxy: StorageProxyType = {
  Storage: new BrowserStorageService(window.localStorage),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant