-
Notifications
You must be signed in to change notification settings - Fork 79
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
Access Token in Persistent Storage is removed on hard refresh. #45
Comments
I have a PR available against master at #46 In case anyone is having the same issue with persist gate not redirecting to the path set up with generateRequireSignInWrapper (mentioned here #35 (comment)) - I have setup a new branch on my fork, that reverts the previous commits and starts off with the currently released NPM version found here - 4 commit behind master - and one ahead - https://github.com/el-rotny/redux-token-auth/tree/old_persistent_header_storage |
This bites lot of people, there are issues in devise-token-auth where people are banging their heads, this shoudl had been merged. |
I wrote this script:
And saved it under And added Works like a charm for now, did not want to rely on outdated or external forks which can be deleted anytime. |
A primer: I am able to intercept Axios requests and responses to make sure access-tokens and and any other header request keys I need replaced in storage and global config.headers - are swapped out on each request. One issue we were facing was to make sure that the headers were not being replaced when they came back empty from devise_token_auth, since at times they will be empty if the token has not yet expired (i.e. after first use). Resolved that through a custom axios interceptor. Navigating through the app and calling authenticated endpoints come back 200 with the correct response, was not happening out of the box for me - solved it in a similar way as below noted.
Feew...Getting tokens from device_token_auth, etc... That is all gravy. The main meat of the issue is how the
verifyCredentials
function is being called. When doing a hard refreshverifyCredentials
gets called which in turn dispatches theverifyToken
action.verifyToken
doesn't seem to be aware of the empty headers and that it shouldn't callpersistAuthHeadersInDeviceStorage(Storage, response.headers)
if the headers are not present, which when it does - it completely squashes the persistent storage keys that will later be used by the next request.Ive verified that setAuthHeaders and peristAuthHeadersInDeviceStorage need some sprucing up -- and keep in mind this is just an example (not familiar with TS as much as es6) where we could check if
the header[key] is there -
const value = headers[key] || fromStorage;
before setting it - wherefromStorage
is the value returned by storage.getItem(key) like below.Another option would be to simply not call
persistAuthHeadersInDeviceStorage
unless the access-token header is actually there. If not it will be replaced with undefined.The verify token action
redux-token-auth/src/actions.ts
Line 169 in 8c5a8fe
The text was updated successfully, but these errors were encountered: