add public fix and pnpm init asst

This commit is contained in:
2025-05-19 22:13:02 +08:00
parent a05f2cd291
commit 5cc1e33b29
9 changed files with 175 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import { app } from '../app.ts';
import { Query } from '@kevisual/query';
import { app, assistantConfig } from '../app.ts';
import './config/index.ts';
import './shop-install/index.ts';
@@ -8,7 +9,34 @@ app
id: 'auth',
})
.define(async (ctx) => {
//
const config = assistantConfig.getConfig();
const { auth } = config;
const host = config.pageApi || config.registry || 'https://kevisual.cn';
const url = new URL('/api/router', host);
const token = ctx.token;
if (auth && auth.type !== 'public') {
if (!token) {
return ctx.throw(4001, 'not login');
}
url.searchParams.set('token', token);
// 鉴权代理
// TODO:
const query = new Query({ baseURL: url.toString() });
const res = await query.post({
path: 'user',
key: 'me',
});
console.log('res', res);
if (res.code !== 200) {
return ctx.throw(4001, 'not login');
}
const tokenUser = res.data || {};
ctx.state = {
...ctx.state,
tokenUser,
};
const { username } = tokenUser;
}
})
.addTo(app);