mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 04:46:05 +00:00
refactor: extracted auth as middleware to be added manually to endpoints
This commit is contained in:
26
app/src/modules/Controller.ts
Normal file
26
app/src/modules/Controller.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { auth, permission } from "auth/middlewares";
|
||||
import { Hono } from "hono";
|
||||
import type { ServerEnv } from "modules/Module";
|
||||
|
||||
export class Controller {
|
||||
protected middlewares = {
|
||||
auth,
|
||||
permission
|
||||
}
|
||||
|
||||
protected create({ auth }: { auth?: boolean } = {}): Hono<ServerEnv> {
|
||||
const server = Controller.createServer();
|
||||
if (auth !== false) {
|
||||
server.use(this.middlewares.auth);
|
||||
}
|
||||
return server;
|
||||
}
|
||||
|
||||
static createServer(): Hono<ServerEnv> {
|
||||
return new Hono<ServerEnv>();
|
||||
}
|
||||
|
||||
getController(): Hono<ServerEnv> {
|
||||
return this.create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user