mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 16:16:02 +00:00
79ca2a9939
* reworked auth architecture with improved password handling and claims Refactored password strategy to prepare supporting bcrypt, improving hashing/encryption flexibility. Updated authentication flow with enhanced user resolution mechanisms, safe JWT generation, and consistent profile handling. Adjusted dependencies to include bcryptjs and updated lock files accordingly. * fix strategy forms handling, add register route and hidden fields Refactored strategy forms to include hidden fields for type and name. Added a registration route with necessary adjustments to the admin controller and routes. Corrected field handling within relevant forms and components. * refactored auth handling to support bcrypt, extracted user pool * update email regex to allow '+' and '_' characters * update test stub password for AppAuth spec * update data exceptions to use HttpStatus constants, adjust logging level in AppUserPool * rework strategies to extend a base class instead of interface * added simple bcrypt test
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { Exception } from "core";
|
|
import { HttpStatus, type TypeInvalidError } from "core/utils";
|
|
import type { Entity } from "./entities";
|
|
import type { Field } from "./fields";
|
|
|
|
export class UnableToConnectException extends Exception {
|
|
override name = "UnableToConnectException";
|
|
override code = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
}
|
|
|
|
export class InvalidSearchParamsException extends Exception {
|
|
override name = "InvalidSearchParamsException";
|
|
override code = HttpStatus.UNPROCESSABLE_ENTITY;
|
|
}
|
|
|
|
export class TransformRetrieveFailedException extends Exception {
|
|
override name = "TransformRetrieveFailedException";
|
|
override code = HttpStatus.UNPROCESSABLE_ENTITY;
|
|
}
|
|
|
|
export class TransformPersistFailedException extends Exception {
|
|
override name = "TransformPersistFailedException";
|
|
override code = HttpStatus.UNPROCESSABLE_ENTITY;
|
|
|
|
static invalidType(property: string, expected: string, given: any) {
|
|
const givenValue = typeof given === "object" ? JSON.stringify(given) : given;
|
|
const message =
|
|
`Property "${property}" must be of type "${expected}", ` +
|
|
`"${givenValue}" of type "${typeof given}" given.`;
|
|
return new TransformPersistFailedException(message);
|
|
}
|
|
|
|
static required(property: string) {
|
|
return new TransformPersistFailedException(`Property "${property}" is required`);
|
|
}
|
|
}
|
|
|
|
export class InvalidFieldConfigException extends Exception {
|
|
override name = "InvalidFieldConfigException";
|
|
override code = HttpStatus.BAD_REQUEST;
|
|
|
|
constructor(
|
|
field: Field<any, any, any>,
|
|
public given: any,
|
|
error: TypeInvalidError,
|
|
) {
|
|
console.error("InvalidFieldConfigException", {
|
|
given,
|
|
error: error.firstToString(),
|
|
});
|
|
super(`Invalid Field config given for field "${field.name}": ${error.firstToString()}`);
|
|
}
|
|
}
|
|
|
|
export class EntityNotDefinedException extends Exception {
|
|
override name = "EntityNotDefinedException";
|
|
override code = HttpStatus.BAD_REQUEST;
|
|
|
|
constructor(entity?: Entity | string) {
|
|
if (!entity) {
|
|
super("Cannot find an entity that is undefined");
|
|
} else {
|
|
super(`Entity "${typeof entity !== "string" ? entity.name : entity}" not defined`);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class EntityNotFoundException extends Exception {
|
|
override name = "EntityNotFoundException";
|
|
override code = HttpStatus.NOT_FOUND;
|
|
|
|
constructor(entity: Entity | string, id: any) {
|
|
super(
|
|
`Entity "${typeof entity !== "string" ? entity.name : entity}" with id "${id}" not found`,
|
|
);
|
|
}
|
|
}
|