fix: fix错误
This commit is contained in:
27
src/route.ts
27
src/route.ts
@@ -1,8 +1,7 @@
|
||||
// import './demo/index.ts';
|
||||
// import { app as adminApp, appendTo } from './admin/index.ts';
|
||||
import './routes/index.ts';
|
||||
import { app } from './app.ts';
|
||||
import { useConfig } from '@kevisual/use-config';
|
||||
import { User } from './models/user.ts';
|
||||
import { createAuthRoute } from '@kevisual/auth';
|
||||
const config = useConfig<{ tokenSecret: string }>();
|
||||
|
||||
@@ -16,18 +15,28 @@ app
|
||||
path: 'auth',
|
||||
key: 'admin',
|
||||
id: 'auth-admin',
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
// ctx.body = 'admin';
|
||||
const token = ctx.query?.token;
|
||||
//
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id: tokenUser.id,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
ctx.throw(404, 'user not found');
|
||||
}
|
||||
const orgs = await user.getOrgs();
|
||||
|
||||
if (orgs.includes('admin')) {
|
||||
ctx.body = 'admin';
|
||||
} else {
|
||||
ctx.throw(403, 'forbidden');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
// app.importApp(adminApp);
|
||||
|
||||
// appendTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'test',
|
||||
|
||||
Reference in New Issue
Block a user