-
Notifications
You must be signed in to change notification settings - Fork 0
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 token #30
Refresh token #30
Changes from 8 commits
85f4e27
99b2e86
36ac05e
81f5496
b3a112e
03aac25
506a31b
cbf9409
b5a40d2
3182d83
80d0ea7
0900c5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v12.18.3 | ||
v14.15.0 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,12 @@ | |
"bcrypt": "5.0.0", | ||
"bootstrap": "4.5.2", | ||
"cors": "2.8.5", | ||
"dotenv": "8.2.0", | ||
"express": "4.17.1", | ||
"express-async-handler": "1.1.4", | ||
"gatsby": "2.24.52", | ||
"gatsby": "2.25.2", | ||
"gatsby-plugin-create-client-paths": "2.3.11", | ||
"gatsby-plugin-nodejs": "0.7.0", | ||
"gatsby-plugin-nodejs": "0.6.4", | ||
Comment on lines
-26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the build issue you were seeing was caused by other issues and these downgrades can probably be reverted |
||
"gatsby-plugin-styled-components": "3.3.12", | ||
"http-errors": "1.8.0", | ||
"jsonwebtoken": "8.5.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ const User = require('../models/user'); | |
const passport = require('passport'); | ||
const jwt = require('jsonwebtoken'); | ||
const createError = require('http-errors'); | ||
const dotenv = require('dotenv'); | ||
|
||
dotenv.config({ path: '.env' }); | ||
|
||
const checkMongoError = (ex) => { | ||
if (ex.name === 'ValidationError') { | ||
|
@@ -104,7 +107,26 @@ exports.loginUser = async (req, res, next) => { | |
if (err) return next(err); | ||
|
||
const body = { _id: user._id, email: user.email }; | ||
const token = jwt.sign({ user: body }, 'TOP_SECRET'); | ||
const token = jwt.sign( | ||
{ user: body }, | ||
process.env.TOKEN_SECRET, | ||
{ | ||
expiresIn: 120, | ||
}); | ||
|
||
const refreshToken = jwt.sign( | ||
{ user: body }, | ||
process.env.REFRESH_TOKEN_SECRET, | ||
); | ||
Comment on lines
+117
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this refresh token should probably have some expiration like 24 hours or something |
||
|
||
await User.findByIdAndUpdate( | ||
user._id, | ||
{ $set: | ||
{ refreshToken }, | ||
}, | ||
{ useFindAndModify: false, | ||
new: true }, | ||
); | ||
|
||
return res.json({ token, info }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
it might help to get a complete picture to update the logout route to delete the refresh token in this iteration? also it looks like this implementation doesnt pass the refresh token back to the user but i read a few articles on this and it looks like they all suggest passing the refresh token back to the user. and then when the user needs to get a fresh token, it passes that refresh token in the request. otherwise anyone could get a refreshed token without auth? also it would help if you also implemented the route for refreshing the token in this iteration (assuming you're implementing refresh in that way) so we can make sure refreshing a token automatically works. it's probably good tho to ya at least defer the frontend implementation for this to a separate PR |
||
}, | ||
|
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.
nice this looks like the new LTS for node but now you should also make sure the Dockerfile and github workflows are updated to also use this node version
you could update your github actions to automatically use the value in the nvmrc
or it looks like
nvm
was added to the github action virtual environments so you could also just update your github actions to use nvm directly