Create and validate signed JSON Web Tokens using SHA-512.
npm install --save signed-jwt
const Token = require('signed-jwt');
const secret = 'iXytm8N6ZFmcWbCUfHC3u7mDmX4e0M1b';
const myToken = Token({ 'id': 1, 'role': 'admin' }, secret);
console.log(`Your token: ${myToken}`);
if (Token.validate(myToken, secret))
console.log('Your token is valid!');
else
console.log('Your token is not valid.');
Kind: global class
Param | Type | Description |
---|---|---|
customObj | object |
an object literal which contains customized information |
secret | string |
secret key |
[validTime] | number |
the amount of miliseconds the token is valid for. Defaults to 2592000000 (30 days) |
Checks if an access token is valid
Kind: static method of Token
Param | Type | Description |
---|---|---|
token | string |
the access token |
secret | string |
secret key |