Add email verification flow#7
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/amalgamated-tools/goauth/sessions/231b8073-f099-43f4-9313-9458cfdfb80e Co-authored-by: veverkap <22348+veverkap@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
veverkap
April 16, 2026 23:54
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an email verification flow to the auth/handler layers so applications can require users to verify their email before logging in.
Changes:
- Introduces
EmailVerificationHandlerwith endpoints to send and verify email verification tokens. - Extends
auth.User/handler.UserDTOwithEmailVerifiedand blocks login whenAuthHandler.RequireVerificationis enabled. - Adds
EmailVerificationToken+EmailVerificationStoreinterface, plus new handler-level tests covering the flow.
Show a summary per file
| File | Description |
|---|---|
handler/email_verification.go |
New HTTP endpoints for sending/consuming verification tokens and marking users verified. |
handler/email_verification_test.go |
New tests for send/verify endpoints and RequireVerification login behavior. |
handler/auth.go |
Adds RequireVerification gate in Login and exposes email_verified in UserDTO. |
auth/types.go |
Adds EmailVerified, new sentinel error, and email verification store/token types. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 4
Comment on lines
+25
to
+31
| Users auth.UserStore | ||
| JWT *auth.JWTManager | ||
| CookieName string | ||
| SecureCookies bool | ||
| DisableSignup bool | ||
| RequireVerification bool | ||
| Verifications auth.EmailVerificationStore |
There was a problem hiding this comment.
AuthHandler now includes an exported Verifications field that is not used anywhere in this file. Leaving unused exported fields increases API surface and (because this is a public struct) creates avoidable compatibility risk for any consumers using positional composite literals. Consider removing this field until it’s needed, or wiring it into behavior in this PR.
Suggested change
| Users auth.UserStore | |
| JWT *auth.JWTManager | |
| CookieName string | |
| SecureCookies bool | |
| DisableSignup bool | |
| RequireVerification bool | |
| Verifications auth.EmailVerificationStore | |
| Users auth.UserStore | |
| JWT *auth.JWTManager | |
| CookieName string | |
| SecureCookies bool | |
| DisableSignup bool | |
| RequireVerification bool |
Resolved conflict in auth/types.go by combining email verification errors/interfaces from this branch with TOTP and password reset errors/interfaces from main.
…ent account enumeration
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.
Users can sign up but cannot log in until their email address is verified. Verification uses the same SHA-256 hash-of-random-token pattern as API keys.
authpackageUsergainsEmailVerified boolErrEmailNotVerifiedsentinel addedEmailVerificationTokenstruct andEmailVerificationStoreinterface:CreateEmailVerification— stores SHA-256 hash of plaintext tokenConsumeEmailVerification— single-use lookup-and-delete by hash; returnssql.ErrNoRowswhen not foundSetEmailVerified— marks user verifiedhandlerpackageEmailVerificationHandler(new file) — two public endpoints:SendVerification(POST) — generates 32-byte random token, stores hash, callsSendEmail(ctx, to, plaintext). Always returns200regardless of whether the address is registered.VerifyEmail(GET?token=…) — re-hashes token, consumes record, checks expiry, callsSetEmailVerified.AuthHandlerchanges:RequireVerification bool— when set,Loginreturns403for unverified users.UserDTOgainsemail_verifiedJSON field.Usage sketch