fix: change to release script to config directory
This commit is contained in:
35
src/route.ts
35
src/route.ts
@@ -15,24 +15,35 @@ app
|
||||
path: 'auth',
|
||||
key: 'admin',
|
||||
id: 'auth-admin',
|
||||
isDebug: true,
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id: tokenUser.id,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
ctx.throw(404, 'user not found');
|
||||
if (!tokenUser) {
|
||||
ctx.throw(401, 'No User For authorized');
|
||||
}
|
||||
const orgs = await user.getOrgs();
|
||||
try {
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id: tokenUser.id,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
ctx.throw(404, 'user not found');
|
||||
}
|
||||
user.setTokenUser(tokenUser);
|
||||
const orgs = await user.getOrgs();
|
||||
|
||||
if (orgs.includes('admin')) {
|
||||
ctx.body = 'admin';
|
||||
} else {
|
||||
ctx.throw(403, 'forbidden');
|
||||
if (orgs.includes('admin')) {
|
||||
ctx.body = 'admin';
|
||||
ctx.nextQuery = ctx.query;
|
||||
} else {
|
||||
ctx.throw(403, 'forbidden');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('auth-admin error', e);
|
||||
ctx.throw(500, e.message);
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user