mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
fix events reference for instance checks
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
enumm,
|
enumm,
|
||||||
Exception,
|
Exception,
|
||||||
text,
|
text,
|
||||||
|
DatabaseEvents,
|
||||||
type App,
|
type App,
|
||||||
type AppPlugin,
|
type AppPlugin,
|
||||||
type DB,
|
type DB,
|
||||||
@@ -13,7 +14,6 @@ import {
|
|||||||
type EntityConfig,
|
type EntityConfig,
|
||||||
} from "bknd";
|
} from "bknd";
|
||||||
import { invariant, s, jsc, HttpStatus, threwAsync, randomString } from "bknd/utils";
|
import { invariant, s, jsc, HttpStatus, threwAsync, randomString } from "bknd/utils";
|
||||||
import { MutatorDeleteBefore, MutatorInsertBefore, MutatorUpdateBefore } from "data/events";
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
export type OtpPluginOptions = {
|
export type OtpPluginOptions = {
|
||||||
@@ -93,6 +93,7 @@ export function otp({
|
|||||||
entityConfig ?? {
|
entityConfig ?? {
|
||||||
name: "Users OTP",
|
name: "Users OTP",
|
||||||
sort_dir: "desc",
|
sort_dir: "desc",
|
||||||
|
primary_format: app.module.data.config.default_primary_format,
|
||||||
},
|
},
|
||||||
"generated",
|
"generated",
|
||||||
),
|
),
|
||||||
@@ -103,7 +104,6 @@ export function otp({
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
onBuilt: async () => {
|
onBuilt: async () => {
|
||||||
// @todo: check if email driver is registered
|
|
||||||
const auth = app.module.auth;
|
const auth = app.module.auth;
|
||||||
invariant(auth && auth.enabled === true, "[OTP Plugin]: Auth is not enabled");
|
invariant(auth && auth.enabled === true, "[OTP Plugin]: Auth is not enabled");
|
||||||
invariant(app.drivers?.email, "[OTP Plugin]: Email driver is not registered");
|
invariant(app.drivers?.email, "[OTP Plugin]: Email driver is not registered");
|
||||||
@@ -300,17 +300,12 @@ function registerListeners(app: App, entityName: string) {
|
|||||||
(event) => {
|
(event) => {
|
||||||
let allowed = true;
|
let allowed = true;
|
||||||
let action = "";
|
let action = "";
|
||||||
if (event instanceof MutatorInsertBefore) {
|
if (event instanceof DatabaseEvents.MutatorInsertBefore) {
|
||||||
if (event.params.entity.name === entityName) {
|
if (event.params.entity.name === entityName) {
|
||||||
allowed = false;
|
allowed = false;
|
||||||
action = "create";
|
action = "create";
|
||||||
}
|
}
|
||||||
} else if (event instanceof MutatorDeleteBefore) {
|
} else if (event instanceof DatabaseEvents.MutatorUpdateBefore) {
|
||||||
if (event.params.entity.name === entityName) {
|
|
||||||
allowed = false;
|
|
||||||
action = "delete";
|
|
||||||
}
|
|
||||||
} else if (event instanceof MutatorUpdateBefore) {
|
|
||||||
if (event.params.entity.name === entityName) {
|
if (event.params.entity.name === entityName) {
|
||||||
allowed = false;
|
allowed = false;
|
||||||
action = "update";
|
action = "update";
|
||||||
@@ -318,7 +313,7 @@ function registerListeners(app: App, entityName: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
throw new Exception(`[OTP Plugin]: Not allowed ${action} OTP codes manually`);
|
throw new Exception(`[OTP Plugin]: Not allowed to ${action} OTP codes manually`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user