add public fix and pnpm init asst
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user