feat(auth): add two-factor authentication - #65
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| those policy variables, rebuild the app, or the auth pages will keep advertising the old | ||
| capabilities (the server still enforces its own policy either way). | ||
|
|
||
| Every account can enable TOTP two-factor authentication from the signed-in user menu. Setup at |
There was a problem hiding this comment.
🟠 High README.md:194
OAuth-only accounts cannot enable TOTP, so the statement that Every account can enable it is incorrect. With allowPasswordless disabled, /two-factor/enable requires validatePassword, which returns false when no password credential exists; either support enrollment for OAuth-only users or qualify this documentation.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @README.md around line 194:
OAuth-only accounts cannot enable TOTP, so the statement that `Every account can enable` it is incorrect. With `allowPasswordless` disabled, `/two-factor/enable` requires `validatePassword`, which returns false when no password credential exists; either support enrollment for OAuth-only users or qualify this documentation.
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a complete two-factor authentication capability with new sign-in challenges, enrollment and recovery flows, trusted-device behavior, and persistent authentication data. Because it changes sensitive authentication paths and includes an unresolved OAuth-only account limitation, the security and runtime behavior warrant human review. Not approved because:
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Summary
/two-factorWhy
Accounts currently authenticate with a single factor. This change adds password-confirmed TOTP enrollment, one-time backup codes, trusted-device support, and the matching sign-in challenge without moving authentication policy into the dashboard or persistence concerns into the auth package.
packages/authowns Better Auth policy,packages/databaseowns the schema and migration, andapps/dashboardremains the composition and presentation boundary.Verification
aube run check:repo— blocked by pre-existingturborepo-monoreposkill frontmatter errorsaube run lint:ci— targeted auth/database/dashboard lint passed; the full command was not completed in this Windows environmentaube run typecheck— auth, database, and dashboard filters passed; the full workspace command timed out without diagnosticsaube test—aube run test --filter=@agent-zero/auth --filter=@agent-zero/databasepassed (65 tests)aube run build— the dashboard production build passed; the root wrapper is blocked by existing Windows aube/junction issuesManual production-preview verification covered enrollment, QR/TOTP confirmation, backup-code generation, a fresh password sign-in redirect, TOTP completion, and trusted-device session creation. The signed-out Playwright challenge scenario also passed. Nuxt component tests remain blocked by the existing
file:///__uno.csstest-environment failure, which reproduces on the unchanged login spec.Safety and compatibility
observemode as read-only, or explained the policy change above.The migration is additive. Better Auth encrypts TOTP secrets and backup codes with the deployment auth secret before persistence, requires the account password for enrollment and disable operations, and marks two-factor enabled only after the first valid TOTP code.
Agent context
Reviewer notes
aube run db:migratebefore exercising two-factor enrollment against an existing database./two-factorroute rule: the page serves both the pending pre-session challenge and authenticated account management, while Better Auth enforces the appropriate cookie/session on each endpoint.Note
Add TOTP two-factor authentication with enrollment, challenge, and backup codes
twoFactorplugin in auth.ts and a new/two-factorroute in two-factor.vue that serves both pre-session second-factor challenges and authenticated enrollment0004_outstanding_mister_sinisteradding thetwo_factortable andtwo_factor_enabledcolumn onuserin schema/auth.ts; the schema is exported through the aggregated schema so Better Auth can resolve the modelqrcode) and one-time backup codes, verifies the first TOTP code before completing setup, and supports disabling with password confirmationTwoFactorErrorcomponent, e2e and unit tests, and docs in README and architecture/two-factorhas auth disabled via route rule in nuxt.config.ts to allow both challenge and enrollment states on the same route; the in-memory e2e adapter in server/auth.config.ts now initializes an emptytwoFactorcollection📊 Macroscope summarized fad036e. 14 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues