feat: update org operate

This commit is contained in:
2025-02-28 13:35:13 +08:00
parent 409067f13f
commit d2280f6b89
14 changed files with 542 additions and 400 deletions

View File

@@ -46,6 +46,46 @@ app
}
})
.addTo(app);
app
.route({
path: 'auth-check',
key: 'admin',
id: 'check-auth-admin',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
if (!tokenUser) {
ctx.throw(401, 'No User For authorized');
}
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';
ctx.state.tokenAdmin = {
id: user.id,
username: user.username,
orgs,
};
return;
}
ctx.body = 'not admin';
} catch (e) {
console.error(`auth-admin error`, e);
console.error('tokenUser', tokenUser?.id, tokenUser?.username, tokenUser?.uid);
ctx.throw(500, e.message);
}
})
.addTo(app);
app
.route({