49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import * as v from "valibot";
|
|
|
|
export const startVerificationSchema = v.object({
|
|
userId: v.string(),
|
|
sessionId: v.string(),
|
|
});
|
|
|
|
export const verifyCodeSchema = v.object({
|
|
verificationToken: v.string(),
|
|
code: v.string(),
|
|
});
|
|
|
|
export const enable2FACodeSchema = v.object({
|
|
code: v.string(),
|
|
});
|
|
|
|
export const disable2FASchema = v.object({
|
|
code: v.string(),
|
|
});
|
|
|
|
export const twoFactorSchema = v.object({
|
|
id: v.string(),
|
|
secret: v.string(),
|
|
backupCodes: v.array(v.string()),
|
|
userId: v.string(),
|
|
createdAt: v.date(),
|
|
updatedAt: v.date(),
|
|
});
|
|
export type TwoFactor = v.InferOutput<typeof twoFactorSchema>;
|
|
|
|
export type TwoFaSessionStatus = "pending" | "verified" | "failed" | "expired";
|
|
|
|
export const twoFaSessionSchema = v.object({
|
|
id: v.string(),
|
|
userId: v.string(),
|
|
sessionId: v.string(),
|
|
verificationToken: v.string(),
|
|
codeUsed: v.optional(v.string()),
|
|
status: v.picklist(["pending", "verified", "failed", "expired"]),
|
|
attempts: v.number(),
|
|
maxAttempts: v.number(),
|
|
verifiedAt: v.optional(v.date()),
|
|
expiresAt: v.date(),
|
|
createdAt: v.date(),
|
|
ipAddress: v.string(),
|
|
userAgent: v.string(),
|
|
});
|
|
export type TwoFaSession = v.InferOutput<typeof twoFaSessionSchema>;
|