backend/helpers/generateToken.js

18 lines
327 B
JavaScript

const jwt = require('jsonwebtoken');
const { jwt_secret } = require('../config/config');
function generateToken(user) {
const payload = {
username: user.username,
email: user.email,
};
const options = {
expiresIn: '30d',
};
return jwt.sign(payload, jwt_secret, options);
}
exports.generateToken = generateToken;