-
Notifications
You must be signed in to change notification settings - Fork 21
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
Refresh accessToken when JWT access token has expired #1120
Conversation
@kristoferlund |
packages/frontend/src/utils/axios.ts
Outdated
delete recoilPersist!['ActiveTokenSet']; | ||
localStorage.setItem(JSON.stringify(recoilPersist), 'recoil-persist'); |
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.
@kristoferlund
It seems we just can use recoil
inside components so I had to manually put/get to local storage
related #1007
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.
Sorry for slow review @mohammadranjbarz!
I'd like to see two small changes, other than that all good!
Or btw. Have you tried how the user experience is when token expires and gets refreshed? Since the original request fails, the UI is left in an unclear state. Should we force a UI reload to make sure all looks good?
packages/frontend/src/utils/axios.ts
Outdated
recoilPersist && | ||
err?.response?.status === 401 && | ||
// 1092, 1107 are the error codes for invalid jwt token that defined in backend | ||
(err?.response?.data?.code === 1092 || err?.response?.data?.code === 1107) |
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.
1092 means unauthenticated user trying to access authenticated resource. This should not trigger a refresh.
packages/frontend/src/utils/axios.ts
Outdated
}> | ||
> => { | ||
let refreshToken; | ||
const recoilPersist = localStorage.getItem('recoil-persist'); |
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.
Use getRecoil(ActiveTokenSet)
, see auth.ts
for example.
@mohammadranjbarz I finished this as I want to get it out to communities soon. |
Thanks @kristoferlund , sorry I was busy last week , I couldn't spend time on this |
related #1007