-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implementing refresh token #58
base: master
Are you sure you want to change the base?
Conversation
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
role: user.role, | ||
}, | ||
process.env.JWT_SECRET, | ||
{ expiresIn: 60 }, |
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 expiration time has to be at least 15-30 minutes.
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.
hmm, don't know if there is a rule in this case or not , but I can put it for 20 minutes
@@ -1,6 +1,6 @@ | |||
/* eslint-disable arrow-parens */ |
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.
some tests are failing
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 should change some stuff in tests but havent done yet
|
||
export const refreshUserToken = (req, res) => { | ||
const token = generateToken(req.user); | ||
res.status(201).json({ token }); |
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.
it not clear what is what here, can you rename it so it is clear what is "refresh token" and what is "access token"
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.
refreshtoken is written refresh token everywhere, and when there is token it is the access token
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.
this function is kinda confusing, so its called refreshUserToken but then it generates a new access token? can you maybe explain us the exact logic of token refreshing to us?
username: user.username, | ||
role: user.role, | ||
}, | ||
process.env.JWT_SECRET, |
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.
do we need to use here maybe other secret for refresh token?
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.
they can be the same as well
role: user.role, | ||
}, | ||
process.env.JWT_SECRET, | ||
{ expiresIn: '30d' }, |
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 tried to test refreshing logic so I set { expiresIn: 2 }
but it did not work and gave me infinite error:
2021-07-21 13:25:37 error: Invalid token
POST /api/refreshToken 401 0.544 ms - 27
also FE did not handle it and did not log me out
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 checked every step in BE & FE by console logging and also checking in the actual app at the same time . I could get both token and refreshtoken in logs
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 also got the same result ://
router.route('/deleteUser').delete(deleteUser); | ||
router.route('/refreshToken').post(verifyToken, refreshUserToken); |
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.
where do you check if there is refresh token? shouldnt u check refresh token first and then verify access token?
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.
it seems like the logic checking actual refresh token is missing
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.
bc refresh token carries the information to get a new (access) token
No description provided.