37 lines
988 B
TypeScript
37 lines
988 B
TypeScript
import * as plugins from '../plugins.js';
|
|
import type { MfaManager } from './classes.mfamanager.js';
|
|
|
|
@plugins.smartdata.Manager()
|
|
export class WebAuthnChallenge extends plugins.smartdata.SmartDataDbDoc<WebAuthnChallenge, any, MfaManager> {
|
|
@plugins.smartdata.unI()
|
|
public id: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public data = {
|
|
userId: null as string | null,
|
|
username: null as string | null,
|
|
mfaChallengeId: null as string | null,
|
|
type: 'login' as 'registration' | 'login' | 'mfa',
|
|
challenge: '',
|
|
status: 'pending' as 'pending' | 'completed' | 'expired',
|
|
createdAt: 0,
|
|
expiresAt: 0,
|
|
completedAt: null as number | null,
|
|
};
|
|
|
|
public isExpired(nowArg = Date.now()) {
|
|
return this.data.expiresAt < nowArg;
|
|
}
|
|
|
|
public async markCompleted() {
|
|
this.data.status = 'completed';
|
|
this.data.completedAt = Date.now();
|
|
await this.save();
|
|
}
|
|
|
|
public async markExpired() {
|
|
this.data.status = 'expired';
|
|
await this.save();
|
|
}
|
|
}
|