var jwt = require('jsonwebtoken'); let Auth = {} const tokenSecretKey = process.env.JSON_KEY Auth.createToken = (userId, masterKey) => { const signedData = {'id':userId, 'date':Date.now(), 'masterKey':masterKey} const token = jwt.sign(signedData, tokenSecretKey) return token } Auth.decodeToken = (token) => { return new Promise((resolve, reject) => { jwt.verify(token, tokenSecretKey, function(err, decoded){ if(err || decoded.id == undefined){ reject('Bad Token') return } //Pass back decoded token resolve(decoded) return }); }) } module.exports = Auth