2020-05-10 22:03:48 +00:00
|
|
|
const jwt = require('jsonwebtoken');
|
2020-08-29 08:48:21 +00:00
|
|
|
const { jwtSecret } = require('../config/config');
|
2020-05-10 22:03:48 +00:00
|
|
|
|
|
|
|
function generateToken(user) {
|
|
|
|
const payload = {
|
|
|
|
username: user.username,
|
|
|
|
email: user.email,
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
expiresIn: '30d',
|
|
|
|
};
|
|
|
|
|
2020-08-29 08:48:21 +00:00
|
|
|
return jwt.sign(payload, jwtSecret, options);
|
2020-05-10 22:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.generateToken = generateToken;
|