feat: add email-otp plugin#6
Open
ibxbit wants to merge 1 commit into
Open
Conversation
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.
Adds a passwordless email-OTP plugin (
plugins/email-otp) modeled onbetter-auth's email-otp plugin.
Endpoints
POST /email-otp/send-otp— request OTP (type:sign-in|email-verification)POST /email-otp/sign-in— sign in with OTP, auto-creates userPOST /email-otp/verify-email— mark existing user's email asverified
Programmatic API via
emailotp.Use(auth).SendOTP / SignInWithOTP / VerifyOTP.Defaults (match better-auth)
WithHashStoredOTPfor at-rest HMAC-SHA256 hashing(improvement over better-auth's plain default; opt-in for parity)
Security
core.WithTransaction— race-safeunder concurrent verifies
send-otpreturns generic success for unknownemails / sign-up-disabled mode
sign-in-otp-<email>vsemail-verification-otp-<email>) so codes never cross flows — coveredby tests
Tests
23 unit tests covering happy paths, expiry, wrong-code lockout, attempt
counting, single-use consumption, auto-signup, additional fields
propagation, type isolation, hashed storage, input validation, and
handler-level cookie/status assertions.
go test -race -count=1passes.go vetandgofmtclean.Tested end-to-end
Manually verified against a Neon Postgres instance: send-otp → sign-in
(auto-creates user + sets session cookie) → authenticated
/api/profilecall. Example added at
examples/email-otp/.Deferred to follow-up PRs
sendVerificationOnSignUphookoverrideDefaultEmailVerificationNotes for the reviewer
plugins/email-otp/go.modcarriesreplace github.com/thecodearcher/limen => ../..so it builds before the nextcore release. Remove and bump to
limen v0.1.2when tagging, matchingthe sweep in commit
efdafac.auth.Handler()wasbeing mounted at
/api/auth/without settingWithHTTPBasePath("/api/auth"), so requests 404'd. This PR fixes it forexamples/email-otp/only; the other examples likely have the same bugand could use a separate cleanup PR.
golangci-lint run ./...from root, which won't recurseinto the plugin module. If you want the new plugin linted in CI, the
workflow's lint step needs the same per-module loop the test step has —
happy to follow up.