feat: two-factor authentication with QR code#7
Merged
Merged
Conversation
Premium users can enable 6-digit TOTP (RFC 6238 / SHA-1 / 30s) on their
account. New twofactor package implements generation and verification
inline (no extra dependency) and is covered by the RFC reference test
vectors.
Setup flow:
POST /user/2fa/setup → secret + otpauth:// URI (not yet enabled)
POST /user/2fa/enable → verify code, flip enabled flag
POST /user/2fa/disable → require valid code, clear secret
Login flow change:
GET /auth/verify → if 2FA enabled, returns
{ two_factor_required: true, pending_token }
instead of an api_key
POST /auth/2fa/verify → exchange pending_token + TOTP code for the
real api_key
Pending tokens are stored under the __pending2fa__ sentinel with a
5-minute server-side TTL. Disable still requires a current code so a
stolen api key can't quietly drop the second factor.
Account page renders three states (off, setup pending with secret +
URI for QR, on with disable form). verify.astro renders a code prompt
when the magic-link response signals 2FA. Four locales translated.
Adds qrcode npm dep and a small QRCode.svelte component that renders the otpauth:// URI as a 180px canvas. The 2FA setup card shows it side-by- side with the secret string so users can either scan with their authenticator app or copy the secret manually.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan