diff --git a/src/auth/AuthGuard.ts b/src/auth/AuthGuard.ts index 0ea3827..c24fde9 100644 --- a/src/auth/AuthGuard.ts +++ b/src/auth/AuthGuard.ts @@ -160,6 +160,9 @@ export default class AuthGuard { throw new PendingApprovalAuthError(); } + // Mark auth proof as used + await proof.use?.(); + // Login session.isAuthenticated = true; session.persistent = persistSession; diff --git a/src/auth/AuthProof.ts b/src/auth/AuthProof.ts index 960d119..e868f95 100644 --- a/src/auth/AuthProof.ts +++ b/src/auth/AuthProof.ts @@ -38,4 +38,10 @@ export default interface AuthProof { * instance. */ revoke(): Promise; + + /** + * This method is called when the AuthProof was used in a successful login attempt. + * If you modify the AuthProof, you should make sure changes are persistent. + */ + use?(): Promise; } diff --git a/src/auth/magic_link/MagicLinkController.ts b/src/auth/magic_link/MagicLinkController.ts index 8639e05..402662f 100644 --- a/src/auth/magic_link/MagicLinkController.ts +++ b/src/auth/magic_link/MagicLinkController.ts @@ -141,7 +141,7 @@ export default class MagicLinkController extends Controll } if (await validLink.isAuthorized()) { - validLink.use(); + validLink.useLink(); await validLink.save(); await this.performAction(validLink, req, res); return; diff --git a/src/auth/models/MagicLink.ts b/src/auth/models/MagicLink.ts index b9c5d1b..34845be 100644 --- a/src/auth/models/MagicLink.ts +++ b/src/auth/models/MagicLink.ts @@ -62,7 +62,7 @@ export default class MagicLink extends Model implements AuthProof { return this.used; } - public use(): void { + public useLink(): void { this.used = true; }