Created
February 1, 2018 12:59
-
-
Save Spyna/b36370164b8f68893cb18060ef20671c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jwt = require( 'jsonwebtoken' ); | |
const secret = require( './credentials.json' ).jwt.secret | |
var createToken = ( user ) => { | |
return "thisisthetokenof:" + user.id | |
} | |
module.exports.verify = ( token ) => { | |
try { | |
return jwt.verify( token, secret ); | |
} catch ( e ) { | |
throw new Error('jwt token not verified'); | |
} | |
} | |
module.exports.generateToken = ( user ) => { | |
return jwt.sign( | |
{ | |
sub: user.id, | |
exp: Math.floor( Date.now() / 1000 ) + ( 60 * 60 ) | |
} | |
, secret ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment