Commit a1d98da3 authored by 成旭东's avatar 成旭东

fix

parent 71ff67ce
Pipeline #27896 passed with stage
in 1 minute 50 seconds
......@@ -4,28 +4,16 @@ module.exports = (options: any) => {
return async function(ctx: Context, next: any) {
// 拿到传会数据的header 中的token值
const token = ctx.request.header.authorization;
// const method = ctx.method.toLowerCase();
// if (options.exclude && options.exclude.includes(ctx.path)) {
// await next();
// return;
// }
if (options.exclude && options.exclude.some((item: any) => item.split('/')[2] === ctx.path.split('/')[2])) {
if (options.exclude && options.exclude.includes(ctx.path)) {
await next();
return;
}
// 当前请求时get请求,执行接下来的中间件
if (!token) {
ctx.throw(401, '未登录, 请先登录');
} else {
try {
// 解码token
ctx.app.jwt.verify(token.split(' ')[1], ctx.app.config.jwt.secret);
await next();
} catch (e) {
ctx.throw(401, '登录失效');
}
}
await next();
};
};
import { Application } from 'egg';
export default (app: Application) => {
const { controller, router, jwt } = app;
const { controller, router } = app;
router.post('/api/login', jwt, controller.user.index.login);
router.get('/api/session', jwt, controller.user.index.session);
router.get('/api/session/menus', jwt, controller.user.index.menus);
router.post('/api/login', controller.user.index.login);
router.get('/api/session', controller.user.index.session);
router.get('/api/session/menus', controller.user.index.menus);
router.post('/api/upload/media', controller.util.uploadMedia);
// 新房房源管理
......
......@@ -33,16 +33,14 @@ export default (appInfo: { name: string; }) => {
config.middleware = [
'errorHandler',
'pagination',
// 'jwtMiddle',
'jwtMiddle',
];
// config.jwtMiddle = {
// exclude: [
// '/api/login',
// '/api/upload/**',
// '/api/estate/**',
// ],
// };
config.jwtMiddle = {
exclude: [
'/api/login',
],
};
config.jwt = {
secret: '123456',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment