@@ -4,7 +4,7 @@ const { accounts } = require('../database/models');
|
|||||||
const route = async (req, res) => {
|
const route = async (req, res) => {
|
||||||
const account = await accounts.findOne({
|
const account = await accounts.findOne({
|
||||||
where: {
|
where: {
|
||||||
username: req.user.username
|
id: req.user.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const { accounts } = require('../database/models');
|
|||||||
const route = async (req, res) => {
|
const route = async (req, res) => {
|
||||||
const account = await accounts.findOne({
|
const account = await accounts.findOne({
|
||||||
where: {
|
where: {
|
||||||
username: req.user.username
|
id: req.user.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ const route = async (req, res) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
username: req.user.username
|
id: req.user.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const route = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//generate the JWT
|
//generate the JWT
|
||||||
const tokens = generate(account.username, account.privilege);
|
const tokens = generate(account.id, account.username, account.privilege);
|
||||||
|
|
||||||
//finally
|
//finally
|
||||||
res.status(200).json(tokens);
|
res.status(200).json(tokens);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const route = async (req, res) => {
|
|||||||
hash: hash
|
hash: hash
|
||||||
}, {
|
}, {
|
||||||
where: {
|
where: {
|
||||||
username: req.user.username
|
id: req.user.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ app.get('*', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//startup
|
//startup
|
||||||
server.listen(process.env.WEB_PORT || 3200, (err) => {
|
server.listen(process.env.WEB_PORT || 3200, async (err) => {
|
||||||
database.sync();
|
await database.sync();
|
||||||
console.log(`listening to localhost:${process.env.WEB_PORT || 3200}`);
|
console.log(`listening to localhost:${process.env.WEB_PORT || 3200}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const { tokens } = require('../database/models');
|
|||||||
module.exports = (token) => {
|
module.exports = (token) => {
|
||||||
tokens.destroy({
|
tokens.destroy({
|
||||||
where: {
|
where: {
|
||||||
token
|
token: token || ''
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,15 @@ const jwt = require('jsonwebtoken');
|
|||||||
const { tokens } = require('../database/models');
|
const { tokens } = require('../database/models');
|
||||||
|
|
||||||
//generates a JWT token based on the given arguments
|
//generates a JWT token based on the given arguments
|
||||||
module.exports = (username, privilege) => {
|
module.exports = (id, username, privilege) => {
|
||||||
const content = {
|
const content = {
|
||||||
|
id,
|
||||||
username,
|
username,
|
||||||
privilege
|
privilege
|
||||||
};
|
};
|
||||||
|
|
||||||
const accessToken = jwt.sign(content, process.env.SECRET_ACCESS, { expiresIn: '1m' });
|
const accessToken = jwt.sign(content, process.env.SECRET_ACCESS, { expiresIn: '10m' });
|
||||||
const refreshToken = jwt.sign(content, process.env.SECRET_REFRESH);
|
const refreshToken = jwt.sign(content, process.env.SECRET_REFRESH, { expiresIn: '30d' });
|
||||||
|
|
||||||
tokens.create({ token: refreshToken });
|
tokens.create({ token: refreshToken });
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module.exports = (token, callback) => {
|
|||||||
|
|
||||||
const tokenRecord = tokens.findOne({
|
const tokenRecord = tokens.findOne({
|
||||||
where: {
|
where: {
|
||||||
token
|
token: token || ''
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ module.exports = (token, callback) => {
|
|||||||
return callback(403);
|
return callback(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = generate(user.username, user.privilege);
|
const result = generate(user.id, user.username, user.privilege);
|
||||||
|
|
||||||
destroy(token);
|
destroy(token);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user