This commit is contained in:
robin
2022-07-07 22:16:39 +08:00
parent 264ab8d979
commit a9a4bd0981
86 changed files with 1198 additions and 310 deletions
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
secret : 'sQ6CIfqS4SqF1zZqRZbCDAT5@T]X4fCD',//秘钥
algorithm: 'HS256',//数字签名或 MAC 算法
expiresIn: "7d",//有效期:例如:1000, "2 days", "10h", "7d". 数值被解释为秒数。如果使用字符串,请确保提供时间单位(天、小时等),否则默认使用毫秒单位("120"等于"120ms")。
}
+17
View File
@@ -0,0 +1,17 @@
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}),
}