diff --git a/src/auth/AuthGuard.ts b/src/auth/AuthGuard.ts index 4d645a3..9db2ddc 100644 --- a/src/auth/AuthGuard.ts +++ b/src/auth/AuthGuard.ts @@ -59,7 +59,8 @@ export default abstract class AuthGuard

> { session: Express.Session, proof: P, onLogin?: (user: User) => Promise, - onRegister?: (connection: Connection, user: User) => Promise, + beforeRegister?: (connection: Connection, user: User) => Promise, + afterRegister?: (connection: Connection, user: User) => Promise, ): Promise { if (!await proof.isValid()) throw new InvalidAuthProofError(); if (!await proof.isAuthorized()) throw new UnauthorizedAuthProofError(); @@ -72,9 +73,12 @@ export default abstract class AuthGuard

> { 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; }); diff --git a/src/auth/magic_link/MagicLinkAuthController.ts b/src/auth/magic_link/MagicLinkAuthController.ts index 7d44f4f..ea988d9 100644 --- a/src/auth/magic_link/MagicLinkAuthController.ts +++ b/src/auth/magic_link/MagicLinkAuthController.ts @@ -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({