Gathering detailed insights and metrics for pwegg
Gathering detailed insights and metrics for pwegg
Gathering detailed insights and metrics for pwegg
Gathering detailed insights and metrics for pwegg
npm install pwegg
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
在config/plugin.js 开启插件
'egg-mysql':{
enable: true,
package:'egg-mysql'
},
'egg-cors':{ enable:true, package:'egg-cors' },
在config/config.delault.js 注册插件
'cors':{//后端跨域 origin:'*', allowMethods:'GET,PUT,POST,DELETE' }
password=${password}&secret=hss
return md5(str)
}
module.exports=getPasswordtoken
axios 拦截 挂载 token config.headers.authorization=Cookie.get('token')
封装鉴权 app/middleware/auth.js
'use strict';
const jwt = require('jsonwebtoken');
module.exports = () => {
return async function auth(ctx, next) {
// 获取前端传来的token
const { authorization } = ctx.request.headers;
// 获取token
const token = authorization.split(' ')[1];
try {
// 尝试运行 try函数
jwt.verify(token, '1902A');
await next();
} catch (error) {
// 如果try函数监听到运行失败 运行catch
console.log('解密失败');
ctx.body = {
code: 0,
msg: '请重修登录',
};
}
};
};
eg:
const { router, controller, middleware } = app;
// 获取用户信息
router.post('/api/userinfo', middleware.auth(), controller.login.getUserInfo);
No vulnerabilities found.
No security vulnerabilities found.