-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: make authStorage a single token data source of truth #207
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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