mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
refactor: extracted auth as middleware to be added manually to endpoints
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { CreateUserPayload } from "auth/AppAuth";
|
||||
import { Event } from "core/events";
|
||||
import { Connection, type LibSqlCredentials, LibsqlConnection } from "data";
|
||||
import {
|
||||
@@ -68,6 +69,12 @@ export class App {
|
||||
onFirstBoot: async () => {
|
||||
console.log("[APP] first boot");
|
||||
this.trigger_first_boot = true;
|
||||
},
|
||||
onServerInit: async (server) => {
|
||||
server.use(async (c, next) => {
|
||||
c.set("app", this);
|
||||
await next();
|
||||
})
|
||||
}
|
||||
});
|
||||
this.modules.ctx().emgr.registerEvents(AppEvents);
|
||||
@@ -87,9 +94,11 @@ export class App {
|
||||
//console.log("syncing", syncResult);
|
||||
}
|
||||
|
||||
const { guard, server } = this.modules.ctx();
|
||||
|
||||
// load system controller
|
||||
this.modules.ctx().guard.registerPermissions(Object.values(SystemPermissions));
|
||||
this.modules.server.route("/api/system", new SystemController(this).getController());
|
||||
guard.registerPermissions(Object.values(SystemPermissions));
|
||||
server.route("/api/system", new SystemController(this).getController());
|
||||
|
||||
// load plugins
|
||||
if (this.plugins.length > 0) {
|
||||
@@ -99,8 +108,8 @@ export class App {
|
||||
//console.log("emitting built", options);
|
||||
await this.emgr.emit(new AppBuiltEvent({ app: this }));
|
||||
|
||||
// not found on any not registered api route
|
||||
this.modules.server.all("/api/*", async (c) => c.notFound());
|
||||
|
||||
server.all("/api/*", async (c) => c.notFound());
|
||||
|
||||
if (options?.save) {
|
||||
await this.modules.save();
|
||||
@@ -158,6 +167,10 @@ export class App {
|
||||
static create(config: CreateAppConfig) {
|
||||
return createApp(config);
|
||||
}
|
||||
|
||||
async createUser(p: CreateUserPayload) {
|
||||
return this.module.auth.createUser(p);
|
||||
}
|
||||
}
|
||||
|
||||
export function createApp(config: CreateAppConfig = {}) {
|
||||
@@ -181,4 +194,4 @@ export function createApp(config: CreateAppConfig = {}) {
|
||||
}
|
||||
|
||||
return new App(connection, config.initialConfig, config.plugins, config.options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user