mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 01:55:10 +02:00
Add basic transactions
This commit is contained in:
parent
c8676ce06a
commit
2f328fc719
22 changed files with 548 additions and 459 deletions
|
@ -73,21 +73,23 @@ export async function verifyTotp(
|
|||
let codes;
|
||||
if (valid) {
|
||||
// if valid, enable two-factor authentication; the totp secret is no longer temporary
|
||||
await db
|
||||
.update(users)
|
||||
.set({ twoFactorEnabled: true })
|
||||
.where(eq(users.userId, user.userId));
|
||||
await db.transaction(async (trx) => {
|
||||
await trx
|
||||
.update(users)
|
||||
.set({ twoFactorEnabled: true })
|
||||
.where(eq(users.userId, user.userId));
|
||||
|
||||
const backupCodes = await generateBackupCodes();
|
||||
codes = backupCodes;
|
||||
for (const code of backupCodes) {
|
||||
const hash = await hashPassword(code);
|
||||
const backupCodes = await generateBackupCodes();
|
||||
codes = backupCodes;
|
||||
for (const code of backupCodes) {
|
||||
const hash = await hashPassword(code);
|
||||
|
||||
await db.insert(twoFactorBackupCodes).values({
|
||||
userId: user.userId,
|
||||
codeHash: hash
|
||||
});
|
||||
}
|
||||
await trx.insert(twoFactorBackupCodes).values({
|
||||
userId: user.userId,
|
||||
codeHash: hash
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: send email to user confirming two-factor authentication is enabled
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue