Skip to content

Commit

Permalink
migration doc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mw10013 committed Dec 24, 2023
1 parent a70c911 commit ff08e7a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ model Totp {
active Boolean
attempts Int

// Add `expiresAt` field.
// Add `expiresAt` field and index.
expiresAt DateTime
@@index([expiresAt])
}
```

Expand All @@ -31,8 +32,15 @@ authenticator.use(
// ❗`storeTOTP` and `handleTOTP` are no longer needed (removed).

createTOTP: async (data, expiresAt) => {
// Create the TOTP data in the database along with `expiresAt`.
await db.totp.create({ data, expiresAt })
await prisma.totp.create({ data: { ...data, expiresAt } })

try {
// Delete expired TOTP records.
// Better if this were in scheduled task.
await prisma.totp.deleteMany({ where: { expiresAt: { lt: new Date() } } })
} catch (error) {
console.warn('Error deleting expired TOTP records', error)
}
},
readTOTP: async (hash) => {
// Get the TOTP data from the database.
Expand Down

0 comments on commit ff08e7a

Please sign in to comment.