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
+2 -2
View File
@@ -2,7 +2,7 @@ const jwt = require('jsonwebtoken');
const { tokens } = require('../database/models');
//generates a JWT token based on the given arguments
module.exports = (index, email, username, type, admin, mod) => {
module.exports = async (index, email, username, type, admin, mod) => {
const content = {
index,
email,
@@ -16,7 +16,7 @@ module.exports = (index, email, username, type, admin, mod) => {
const accessToken = jwt.sign(content, process.env.SECRET_ACCESS, { expiresIn: '10m', issuer: 'auth' });
const refreshToken = jwt.sign(content, process.env.SECRET_REFRESH, { expiresIn: '30d', issuer: 'auth' });
tokens.create({ token: refreshToken, email: email });
await tokens.create({ token: refreshToken, email: email });
return { accessToken, refreshToken };
};