Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Implementing refresh token #58

wants to merge 1 commit into from

Conversation

BehnazDer
Copy link
Member

No description provided.

@sonarcloud
Copy link

sonarcloud bot commented Jul 18, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

role: user.role,
},
process.env.JWT_SECRET,
{ expiresIn: 60 },
Copy link
Member

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.

Copy link
Member Author

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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tests are failing

Copy link
Member Author

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 });
Copy link
Member

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"

Copy link
Member Author

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

Copy link
Member

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,
Copy link
Member

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?

Copy link
Member Author

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' },
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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);
Copy link
Member

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?

Copy link
Member

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

Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants