feat: 更新开发脚本,添加新的环境变量支持,优化管理员登录流程
This commit is contained in:
@@ -14,7 +14,7 @@ export const getTokenUser = async (ctx: any) => {
|
||||
const res = await query.post({
|
||||
path: 'user',
|
||||
key: 'me',
|
||||
token: ctx.state.token,
|
||||
token: ctx.state.token || ctx.query.token,
|
||||
});
|
||||
if (res.code !== 200) {
|
||||
return ctx.throw(401, 'not login');
|
||||
@@ -26,7 +26,7 @@ const checkAuth = async (ctx: any, isAdmin = false) => {
|
||||
const config = assistantConfig.getConfig();
|
||||
const { auth = {} } = config;
|
||||
const token = ctx.query.token;
|
||||
|
||||
console.log('checkAuth', ctx.query, { token });
|
||||
if (!token) {
|
||||
return ctx.throw(401, 'not login');
|
||||
}
|
||||
@@ -47,8 +47,17 @@ const checkAuth = async (ctx: any, isAdmin = false) => {
|
||||
auth.username = username;
|
||||
assistantConfig.setConfig({ auth });
|
||||
}
|
||||
if (isAdmin) {
|
||||
if (auth.username && auth.username !== username) {
|
||||
if (isAdmin && auth.username) {
|
||||
const admins = config.auth?.admin || [];
|
||||
let isCheckAdmin = false;
|
||||
const admin = auth.username;
|
||||
if (admin === username) {
|
||||
isCheckAdmin = true;
|
||||
}
|
||||
if (!isCheckAdmin && admins.length > 0 && admins.includes(username)) {
|
||||
isCheckAdmin = true;
|
||||
}
|
||||
if (!isCheckAdmin) {
|
||||
return ctx.throw(403, 'not admin user');
|
||||
}
|
||||
}
|
||||
@@ -70,6 +79,7 @@ app
|
||||
description: '管理员鉴权, 获取用户信息,并验证是否为管理员。',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
console.log('query', ctx.query);
|
||||
await checkAuth(ctx, true);
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user