backend/helpers/generateToken.js

18 lines
325 B
JavaScript
Raw Normal View History

2020-05-10 22:03:48 +00:00
const jwt = require('jsonwebtoken');
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',
};
return jwt.sign(payload, jwtSecret, options);
2020-05-10 22:03:48 +00:00
}
exports.generateToken = generateToken;