[PR #3844] [CLOSED] feat(2fa): store trusted devices in db #21946

Closed
opened 2026-04-15 20:42:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3844
Author: @frectonz
Created: 8/7/2025
Status: Closed

Base: canaryHead: feat/trusted-devices


📝 Commits (10+)

  • d8d1077 feat: track trusted devices in database
  • b2e305b Merge branch 'canary' into feat/trusted-devices
  • f450f80 feat(two-factor): implement isTrusted
  • 7c55d53 feat(two-factor): implement trustDevice
  • 751b345 fix(two-factor): add trusted devices to schema only if the user requestes the in db strategy for tracking trusted devices
  • d4e431c fix(two-factor): await the trustDevice function call
  • 5015353 fix(two-factor): use the return type of the schema function
  • 88ce859 feat(two-factor): define trusted device endpoints
  • 3418221 feat(two-factor): add userId
  • 24c11c4 fix(two-factor): rename to expires at

📊 Changes

10 files changed (+757 additions, -252 deletions)

View changed files

📝 docs/content/docs/plugins/2fa.mdx (+81 -4)
📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+9 -2)
📝 packages/better-auth/src/plugins/two-factor/index.ts (+36 -46)
📝 packages/better-auth/src/plugins/two-factor/otp/index.ts (+17 -4)
📝 packages/better-auth/src/plugins/two-factor/schema.ts (+61 -30)
📝 packages/better-auth/src/plugins/two-factor/totp/index.ts (+9 -2)
packages/better-auth/src/plugins/two-factor/trusted-device.ts (+353 -0)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+167 -139)
📝 packages/better-auth/src/plugins/two-factor/types.ts (+15 -1)
📝 packages/better-auth/src/plugins/two-factor/verify-two-factor.ts (+9 -24)

📄 Description

Summary by cubic

Added trusted device tracking for two-factor authentication by storing device info in the database and updating how trust device cookies are managed.

  • New Features
    • Devices trusted during 2FA are now saved in a new database table with device ID, user agent, and expiration.
    • Trust device cookies now reference the stored device instead of using HMAC tokens.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3844 **Author:** [@frectonz](https://github.com/frectonz) **Created:** 8/7/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/trusted-devices` --- ### 📝 Commits (10+) - [`d8d1077`](https://github.com/better-auth/better-auth/commit/d8d107796d3760fbb85a6f8ca35fb3afd630ce27) feat: track trusted devices in database - [`b2e305b`](https://github.com/better-auth/better-auth/commit/b2e305b56070e116e66da2110124a9e011125e75) Merge branch 'canary' into feat/trusted-devices - [`f450f80`](https://github.com/better-auth/better-auth/commit/f450f80168cd8e944a0d8c097691a81b2150f3a6) feat(two-factor): implement `isTrusted` - [`7c55d53`](https://github.com/better-auth/better-auth/commit/7c55d53ce46a91600872260487ad60de82f70816) feat(two-factor): implement `trustDevice` - [`751b345`](https://github.com/better-auth/better-auth/commit/751b345819f8a22b5ca29f2becedad73cf19b346) fix(two-factor): add trusted devices to schema only if the user requestes the in db strategy for tracking trusted devices - [`d4e431c`](https://github.com/better-auth/better-auth/commit/d4e431cf58ce55ceb2a91fc4b6362335958b1e9e) fix(two-factor): await the `trustDevice` function call - [`5015353`](https://github.com/better-auth/better-auth/commit/5015353746b6d3cb1c1ba052bd8b44c03a55c793) fix(two-factor): use the return type of the schema function - [`88ce859`](https://github.com/better-auth/better-auth/commit/88ce8599cf732133886f51633cd0237517984d7f) feat(two-factor): define trusted device endpoints - [`3418221`](https://github.com/better-auth/better-auth/commit/3418221e994e8f94bf21e74fcceb03ca5a2d333c) feat(two-factor): add `userId` - [`24c11c4`](https://github.com/better-auth/better-auth/commit/24c11c469eb77019bea106fecb6214b94bf83588) fix(two-factor): rename to expires at ### 📊 Changes **10 files changed** (+757 additions, -252 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/2fa.mdx` (+81 -4) 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+9 -2) 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+36 -46) 📝 `packages/better-auth/src/plugins/two-factor/otp/index.ts` (+17 -4) 📝 `packages/better-auth/src/plugins/two-factor/schema.ts` (+61 -30) 📝 `packages/better-auth/src/plugins/two-factor/totp/index.ts` (+9 -2) ➕ `packages/better-auth/src/plugins/two-factor/trusted-device.ts` (+353 -0) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+167 -139) 📝 `packages/better-auth/src/plugins/two-factor/types.ts` (+15 -1) 📝 `packages/better-auth/src/plugins/two-factor/verify-two-factor.ts` (+9 -24) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Added trusted device tracking for two-factor authentication by storing device info in the database and updating how trust device cookies are managed. - **New Features** - Devices trusted during 2FA are now saved in a new database table with device ID, user agent, and expiration. - Trust device cookies now reference the stored device instead of using HMAC tokens. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 20:42:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#21946