feat(back/auth): add use() method to AuthProof and call it on successful login attempt
This commit is contained in:
parent
0c4349fac3
commit
41a083ba52
@ -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;
|
||||||
|
@ -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>;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user