20 lines
368 B
JavaScript
20 lines
368 B
JavaScript
'use strict'
|
|
|
|
const jwt = require('jwt-simple');
|
|
const moment = require('moment');
|
|
require('dotenv').config();
|
|
|
|
function createToken(user) {
|
|
const payload ={
|
|
sub: user._id,
|
|
iat: moment().unix(),
|
|
exp: moment().add(1, 'days').unix(),
|
|
};
|
|
|
|
return jwt.encode(payload, process.env.SECRET_TOKEN);
|
|
}
|
|
|
|
module.exports = {
|
|
createToken
|
|
};
|