mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-19 05:46:04 +00:00
added onBeforeUpdate listener + auto create a secret on auth enable
This commit is contained in:
@@ -13,7 +13,7 @@ export type ModuleBuildContext = {
|
||||
guard: Guard;
|
||||
};
|
||||
|
||||
export abstract class Module<Schema extends TSchema = TSchema> {
|
||||
export abstract class Module<Schema extends TSchema = TSchema, ConfigSchema = Static<Schema>> {
|
||||
private _built = false;
|
||||
private _schema: SchemaObject<ReturnType<(typeof this)["getSchema"]>>;
|
||||
private _listener: any = () => null;
|
||||
@@ -28,10 +28,15 @@ export abstract class Module<Schema extends TSchema = TSchema> {
|
||||
await this._listener(c);
|
||||
},
|
||||
restrictPaths: this.getRestrictedPaths(),
|
||||
overwritePaths: this.getOverwritePaths()
|
||||
overwritePaths: this.getOverwritePaths(),
|
||||
onBeforeUpdate: this.onBeforeUpdate.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
onBeforeUpdate(from: ConfigSchema, to: ConfigSchema): ConfigSchema | Promise<ConfigSchema> {
|
||||
return to;
|
||||
}
|
||||
|
||||
setListener(listener: (c: ReturnType<(typeof this)["getSchema"]>) => void | Promise<void>) {
|
||||
this._listener = listener;
|
||||
return this;
|
||||
@@ -92,7 +97,8 @@ export abstract class Module<Schema extends TSchema = TSchema> {
|
||||
},
|
||||
forceParse: this.useForceParse(),
|
||||
restrictPaths: this.getRestrictedPaths(),
|
||||
overwritePaths: this.getOverwritePaths()
|
||||
overwritePaths: this.getOverwritePaths(),
|
||||
onBeforeUpdate: this.onBeforeUpdate.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -66,10 +66,16 @@ export class SystemController implements ClassController {
|
||||
console.error(e);
|
||||
|
||||
if (e instanceof TypeInvalidError) {
|
||||
return c.json({ success: false, errors: e.errors }, { status: 400 });
|
||||
return c.json(
|
||||
{ success: false, type: "type-invalid", errors: e.errors },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (e instanceof Error) {
|
||||
return c.json({ success: false, type: "error", error: e.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return c.json({ success: false }, { status: 500 });
|
||||
return c.json({ success: false, type: "unknown" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user