added authentication, $schema, fixed media adapter mcp

This commit is contained in:
dswbx
2025-08-07 11:33:46 +02:00
parent 1b02feca93
commit 42db5f55c7
9 changed files with 247 additions and 34 deletions

View File

@@ -85,9 +85,6 @@ async function create(app: App, options: any) {
async function update(app: App, options: any) {
const config = app.module.auth.toJSON(true);
const strategy = app.module.auth.authenticator.strategy("password") as PasswordStrategy;
const users_entity = config.entity_name as "users";
const em = app.modules.ctx().em;
const email = (await $text({
message: "Which user? Enter email",
@@ -100,7 +97,10 @@ async function update(app: App, options: any) {
})) as string;
if ($isCancel(email)) process.exit(1);
const { data: user } = await em.repository(users_entity).findOne({ email });
const { data: user } = await app.modules
.ctx()
.em.repository(config.entity_name as "users")
.findOne({ email });
if (!user) {
$log.error("User not found");
process.exit(1);
@@ -118,26 +118,10 @@ async function update(app: App, options: any) {
});
if ($isCancel(password)) process.exit(1);
try {
function togglePw(visible: boolean) {
const field = em.entity(users_entity).field("strategy_value")!;
field.config.hidden = !visible;
field.config.fillable = visible;
}
togglePw(true);
await app.modules
.ctx()
.em.mutator(users_entity)
.updateOne(user.id, {
strategy_value: await strategy.hash(password as string),
});
togglePw(false);
if (await app.module.auth.changePassword(user.id, password)) {
$log.success(`Updated user: ${c.cyan(user.email)}`);
} catch (e) {
} else {
$log.error("Error updating user");
$console.error(e);
}
}