feat(back/auth): add use() method to AuthProof and call it on successful login attempt

This commit is contained in:
Alice Gaudon 2022-03-06 16:34:57 +01:00
parent 0c4349fac3
commit 41a083ba52
4 changed files with 11 additions and 2 deletions

View File

@ -160,6 +160,9 @@ export default class AuthGuard {
throw new PendingApprovalAuthError(); throw new PendingApprovalAuthError();
} }
// Mark auth proof as used
await proof.use?.();
// Login // Login
session.isAuthenticated = true; session.isAuthenticated = true;
session.persistent = persistSession; session.persistent = persistSession;

View File

@ -38,4 +38,10 @@ export default interface AuthProof<R> {
* instance. * instance.
*/ */
revoke(): Promise<void>; revoke(): Promise<void>;
/**
* 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<void>;
} }

View File

@ -141,7 +141,7 @@ export default class MagicLinkController<A extends Application> extends Controll
} }
if (await validLink.isAuthorized()) { if (await validLink.isAuthorized()) {
validLink.use(); validLink.useLink();
await validLink.save(); await validLink.save();
await this.performAction(validLink, req, res); await this.performAction(validLink, req, res);
return; return;

View File

@ -62,7 +62,7 @@ export default class MagicLink extends Model implements AuthProof<User> {
return this.used; return this.used;
} }
public use(): void { public useLink(): void {
this.used = true; this.used = true;
} }