feat: 更新开发脚本,添加新的环境变量支持,优化管理员登录流程

This commit is contained in:
2025-12-18 03:47:07 +08:00
parent 5b610fd600
commit 6e1ffe173a
6 changed files with 91 additions and 34 deletions

View File

@@ -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);