feat: make authStorage a single token data source of truth#207
feat: make authStorage a single token data source of truth#207MieszkoTSH wants to merge 4 commits intomasterfrom
Conversation
🦋 Changeset detectedLatest commit: e74933d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
2d8603b to
21fbc5f
Compare
| accessToken: _storage.getItem(ACCESS_TOKEN_KEY), | ||
| refreshToken: _storage.getItem(REFRESH_TOKEN_KEY), | ||
| expires: Number(_storage.getItem(EXPIRES_KEY)), |
There was a problem hiding this comment.
how does this constructor with reading data from storage work with the defaultTokenData in line 14?
| private _refreshToken: string | null = null; | ||
| private _expires: number | null = null; | ||
| private _storage: Storage | null = null; | ||
| private _storage: Storage | null; |
There was a problem hiding this comment.
Explicit typing can be removed, a type will be infered based on the assignment in the constructor
| private _storage: Storage | null; | |
| private _storage; |
| private _expires: number | null = null; | ||
| private _storage: Storage | null = null; | ||
| private _storage: Storage | null; | ||
| private _tokenData: TokenData = defaultTokenData; |
There was a problem hiding this comment.
I think this typing and default value can be omitted. This comment is related to the question here https://github.com/TheSoftwareHouse/react-starter-boilerplate/pull/207/files#r1664081100
|
Removing |
I have missed that 😅. |
| this._tokenData = { | ||
| accessToken: _storage.getItem(ACCESS_TOKEN_KEY), | ||
| refreshToken: _storage.getItem(REFRESH_TOKEN_KEY), | ||
| expires: Number(_storage.getItem(EXPIRES_KEY)), |
There was a problem hiding this comment.
if EXPIRES_KEY does not exist then this line will be Number(null) which will be evaluated to 0, therefore the default value for expires will be 0, which is different than expires in the defaultTokenData object.
There was a problem hiding this comment.
I think we'd need to do sth like expires: _storage.getItem(EXPIRES_KEY) ? Number(_storage.getItem(EXPIRES_KEY)) : defaultTokenData.expires,
There was a problem hiding this comment.
Yup you are right, fixed that
5798006 to
e74933d
Compare
I have changed authStorage to be the singe source of truth for auth tokens data. I tried to keep it pretty close to what we had before, but i have also added some methods that simplify e.g. reseting token data