mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
refactor: extracted auth as middleware to be added manually to endpoints
This commit is contained in:
@@ -35,9 +35,11 @@ async function action(action: "create" | "update", options: any) {
|
||||
}
|
||||
|
||||
async function create(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";
|
||||
|
||||
if (!strategy) {
|
||||
throw new Error("Password strategy not configured");
|
||||
}
|
||||
|
||||
const email = await $text({
|
||||
message: "Enter email",
|
||||
@@ -65,16 +67,11 @@ async function create(app: App, options: any) {
|
||||
}
|
||||
|
||||
try {
|
||||
const mutator = app.modules.ctx().em.mutator(users_entity);
|
||||
mutator.__unstable_toggleSystemEntityCreation(false);
|
||||
const res = await mutator.insertOne({
|
||||
const created = await app.createUser({
|
||||
email,
|
||||
strategy: "password",
|
||||
strategy_value: await strategy.hash(password as string)
|
||||
});
|
||||
mutator.__unstable_toggleSystemEntityCreation(true);
|
||||
|
||||
console.log("Created:", res.data);
|
||||
password: await strategy.hash(password as string)
|
||||
})
|
||||
console.log("Created:", created);
|
||||
} catch (e) {
|
||||
console.error("Error", e);
|
||||
}
|
||||
@@ -141,4 +138,4 @@ async function update(app: App, options: any) {
|
||||
} catch (e) {
|
||||
console.error("Error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user