Fixed a nasty async race condition

This commit is contained in:
2023-06-27 04:25:52 +10:00
parent fd0c40d444
commit 44e19154ab
6 changed files with 11 additions and 13 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ const route = async (req, res) => {
}
//generate the JWTs
const { accessToken, refreshToken } = tokenGenerateRefresh(account.index, account.email, account.username, account.type, account.admin, account.mod);
const { accessToken, refreshToken } = await tokenGenerateRefresh(account.index, account.email, account.username, account.type, account.admin, account.mod);
//set the cookie
res.cookie('refreshToken', refreshToken, { path: '/', httpOnly: true, secure: true, sameSite: 'none', maxAge: 60 * 60 * 24 * 30 * 1000 }); //30 days
+1 -3
View File
@@ -1,10 +1,8 @@
const jwt = require('jsonwebtoken');
const tokenRefresh = require('../utilities/token-refresh');
//auth/token
module.exports = async (req, res) => {
return tokenRefresh(req.cookies.refreshToken || '', (err, accessToken, refreshToken) => {
return await tokenRefresh(req.cookies.refreshToken || '', (err, accessToken, refreshToken) => {
if (err) {
return res.status(err).end();
}