2FA reset feature
This commit is contained in:
1 parent
896d63df94
commit
3b4d5b9575
7 files changed
+262
-28
No files matched your search
@@ -43,3 +43,35 @@ export async function POST(request: Request, { params }: { params: Promise<{ use
|
||||
|
||||
return json({ ok: true, userId: user.id, twoFactorRequired: required });
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const { auth, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!(await canEnforceTwoFactorAuthForUser(auth))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const { userId } = await params;
|
||||
|
||||
const [twoFactorAuth, backupCodes, otpUsed, rateLimit] = await prisma.transaction([
|
||||
prisma.client.twoFactorAuth.deleteMany({ where: { userId } }),
|
||||
prisma.client.twoFactorBackupCode.deleteMany({ where: { userId } }),
|
||||
prisma.client.twoFactorOtpUsed.deleteMany({ where: { userId } }),
|
||||
prisma.client.twoFactorRateLimit.deleteMany({ where: { userId } }),
|
||||
]);
|
||||
|
||||
return json({
|
||||
ok: true,
|
||||
userId,
|
||||
reset: {
|
||||
twoFactorAuth: twoFactorAuth.count,
|
||||
backupCodes: backupCodes.count,
|
||||
otpUsed: otpUsed.count,
|
||||
rateLimit: rateLimit.count,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user