backend/helpers/generateToken.js

18 lines
325 B
JavaScript

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