feat: 注释掉auth中间件中对checkAppId的调用,避免重复验证用户信息
This commit is contained in:
36
src/route.ts
36
src/route.ts
@@ -40,12 +40,12 @@ export const addAuth = (app: App) => {
|
|||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const token = ctx.query.token;
|
const token = ctx.query.token;
|
||||||
if (checkAppId(ctx, app.appId)) {
|
// if (checkAppId(ctx, app.appId)) {
|
||||||
ctx.state.tokenUser = {
|
// ctx.state.tokenUser = {
|
||||||
username: 'default',
|
// username: 'default',
|
||||||
}
|
// }
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
// 已经有用户信息则直接返回,不需要重复验证
|
// 已经有用户信息则直接返回,不需要重复验证
|
||||||
if (ctx.state.tokenUser) {
|
if (ctx.state.tokenUser) {
|
||||||
return;
|
return;
|
||||||
@@ -75,12 +75,12 @@ export const addAuth = (app: App) => {
|
|||||||
description: '验证token,可以不成功,错误不返回401,正确赋值到ctx.state.tokenUser,失败赋值null',
|
description: '验证token,可以不成功,错误不返回401,正确赋值到ctx.state.tokenUser,失败赋值null',
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
if (checkAppId(ctx, app.appId)) {
|
// if (checkAppId(ctx, app.appId)) {
|
||||||
ctx.state.tokenUser = {
|
// ctx.state.tokenUser = {
|
||||||
username: 'default',
|
// username: 'default',
|
||||||
}
|
// }
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
// 已经有用户信息则直接返回,不需要重复验证
|
// 已经有用户信息则直接返回,不需要重复验证
|
||||||
if (ctx.state.tokenUser) {
|
if (ctx.state.tokenUser) {
|
||||||
return;
|
return;
|
||||||
@@ -113,12 +113,12 @@ app
|
|||||||
description: '验证token,必须是admin用户, 错误返回403,正确赋值到ctx.state.tokenAdmin',
|
description: '验证token,必须是admin用户, 错误返回403,正确赋值到ctx.state.tokenAdmin',
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
if (checkAppId(ctx, app.appId)) {
|
// if (checkAppId(ctx, app.appId)) {
|
||||||
ctx.state.tokenUser = {
|
// ctx.state.tokenUser = {
|
||||||
username: 'default',
|
// username: 'default',
|
||||||
}
|
// }
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const tokenUser = ctx.state.tokenUser;
|
const tokenUser = ctx.state.tokenUser;
|
||||||
if (!tokenUser) {
|
if (!tokenUser) {
|
||||||
ctx.throw(401, 'No User For authorized');
|
ctx.throw(401, 'No User For authorized');
|
||||||
|
|||||||
Reference in New Issue
Block a user