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:
@@ -1,6 +1,6 @@
|
||||
import { type AuthAction, Authenticator, type ProfileExchange, Role, type Strategy } from "auth";
|
||||
import type { PasswordStrategy } from "auth/authenticate/strategies";
|
||||
import { Exception, type PrimaryFieldType } from "core";
|
||||
import { type DB, Exception, type PrimaryFieldType } from "core";
|
||||
import { type Static, secureRandomString, transformObject } from "core/utils";
|
||||
import { type Entity, EntityIndex, type EntityManager } from "data";
|
||||
import { type FieldSchema, entity, enumm, make, text } from "data/prototype";
|
||||
@@ -17,6 +17,7 @@ declare module "core" {
|
||||
}
|
||||
|
||||
type AuthSchema = Static<typeof authConfigSchema>;
|
||||
export type CreateUserPayload = { email: string; password: string; [key: string]: any };
|
||||
|
||||
export class AppAuth extends Module<typeof authConfigSchema> {
|
||||
private _authenticator?: Authenticator;
|
||||
@@ -36,8 +37,12 @@ export class AppAuth extends Module<typeof authConfigSchema> {
|
||||
return to;
|
||||
}
|
||||
|
||||
get enabled() {
|
||||
return this.config.enabled;
|
||||
}
|
||||
|
||||
override async build() {
|
||||
if (!this.config.enabled) {
|
||||
if (!this.enabled) {
|
||||
this.setBuilt();
|
||||
return;
|
||||
}
|
||||
@@ -84,14 +89,6 @@ export class AppAuth extends Module<typeof authConfigSchema> {
|
||||
return this._controller;
|
||||
}
|
||||
|
||||
getMiddleware() {
|
||||
if (!this.config.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new AuthController(this).getMiddleware;
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return authConfigSchema;
|
||||
}
|
||||
@@ -287,11 +284,7 @@ export class AppAuth extends Module<typeof authConfigSchema> {
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
async createUser({
|
||||
email,
|
||||
password,
|
||||
...additional
|
||||
}: { email: string; password: string; [key: string]: any }) {
|
||||
async createUser({ email, password, ...additional }: CreateUserPayload): Promise<DB["users"]> {
|
||||
const strategy = "password";
|
||||
const pw = this.authenticator.strategy(strategy) as PasswordStrategy;
|
||||
const strategy_value = await pw.hash(password);
|
||||
|
||||
Reference in New Issue
Block a user