18 lines
543 B
JavaScript
18 lines
543 B
JavaScript
const jwt = require("jsonwebtoken");
|
|
const config = require("./config.js");
|
|
|
|
module.exports = {
|
|
/**
|
|
* 签发token
|
|
* @param {object} data 加入到签名里的数据.
|
|
* @return {string} token 令牌.
|
|
*/
|
|
sign: (data) => jwt.sign(data, config.secret, {algorithm: config.algorithm, expiresIn: config.expiresIn}),
|
|
/**
|
|
* 验证token
|
|
* @param {string} token 令牌.
|
|
* @return {boolean} 验证通过返回true.
|
|
*/
|
|
verify: (token) => jwt.verify(token, config.secret, {algorithm: config.algorithm, expiresIn: config.expiresIn}),
|
|
}
|