AuthGuard: add separate before and after registration callbacks
This commit is contained in:
parent
19066b3e67
commit
d741517cb9
@ -59,7 +59,8 @@ export default abstract class AuthGuard<P extends AuthProof<User>> {
|
||||
session: Express.Session,
|
||||
proof: P,
|
||||
onLogin?: (user: User) => Promise<void>,
|
||||
onRegister?: (connection: Connection, user: User) => Promise<RegisterCallback[]>,
|
||||
beforeRegister?: (connection: Connection, user: User) => Promise<RegisterCallback[]>,
|
||||
afterRegister?: (connection: Connection, user: User) => Promise<RegisterCallback[]>,
|
||||
): Promise<User> {
|
||||
if (!await proof.isValid()) throw new InvalidAuthProofError();
|
||||
if (!await proof.isAuthorized()) throw new UnauthorizedAuthProofError();
|
||||
@ -72,9 +73,12 @@ export default abstract class AuthGuard<P extends AuthProof<User>> {
|
||||
|
||||
user = await MysqlConnectionManager.wrapTransaction(async connection => {
|
||||
const user = User.create({});
|
||||
if (beforeRegister) {
|
||||
(await beforeRegister(connection, user)).forEach(c => callbacks.push(c));
|
||||
}
|
||||
await user.save(connection, c => callbacks.push(c));
|
||||
if (onRegister) {
|
||||
(await onRegister(connection, user)).forEach(c => callbacks.push(c));
|
||||
if (afterRegister) {
|
||||
(await afterRegister(connection, user)).forEach(c => callbacks.push(c));
|
||||
}
|
||||
return user;
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ export default abstract class MagicLinkAuthController extends AuthController {
|
||||
// Auth
|
||||
try {
|
||||
return await req.as(AuthMiddleware).getAuthGuard().authenticateOrRegister(
|
||||
session, magicLink, undefined, async (connection, user) => {
|
||||
session, magicLink, undefined, undefined, async (connection, user) => {
|
||||
const callbacks: RegisterCallback[] = [];
|
||||
|
||||
const userEmail = UserEmail.create({
|
||||
|
Loading…
Reference in New Issue
Block a user