Email Verification
AuthKit provides a configurable, driver-based email verification system that supports both:
- signed link verification
- token/code verification
The flow is controlled through configuration and can be extended or replaced without modifying package internals.
Overview
Email verification in AuthKit has three main phases:
- Verification initiation during registration, login, or resend
- Verification delivery through a signed link or token
- Verification completion when the user verifies the email address
The system is driven by:
authkit.email_verification.enabled
authkit.email_verification.driver
authkit.email_verification.ttl_minutes
authkit.email_verification.columns
authkit.email_verification.post_verify
authkit.email_verification.deliverySupported drivers:
- link
- token
Routes
AuthKit resolves email verification routes from configuration:
authkit.route_names.web.verify_notice
authkit.route_names.web.verify_token_page
authkit.route_names.web.verify_link
authkit.route_names.web.verify_success
authkit.route_names.web.login
authkit.route_names.api.send_verification
authkit.route_names.api.verify_tokenThese routes are used for:
- the verification notice page
- the token entry page
- signed link verification
- the success page
- resend actions
- token verification actions
Verification Flow
1. Triggering verification
Verification is typically triggered when:
- a user registers
- a user logs in but is not verified
- a resend request is made
AuthKit creates a pending verification context through:
Xul\AuthKit\Support\PendingEmailVerificationThat context stores the pending verification token and related metadata such as the user ID and active driver.
2. Delivery
AuthKit does not send verification emails directly from its action classes.
Instead, it dispatches:
Xul\AuthKit\Events\AuthKitEmailVerificationRequiredDelivery behavior is controlled by:
authkit.email_verification.delivery.use_listener
authkit.email_verification.delivery.listener
authkit.email_verification.delivery.notifier
authkit.email_verification.delivery.mode
authkit.email_verification.delivery.queue_connection
authkit.email_verification.delivery.queue
authkit.email_verification.delivery.delayWhen the packaged listener is enabled, AuthKit uses:
Xul\AuthKit\Listeners\SendEmailVerificationNotificationThat listener delegates delivery to the configured notifier implementing:
Xul\AuthKit\Contracts\EmailVerificationNotifierContractSupported delivery modes:
syncqueueafter_response
3. Verification completion
Depending on the configured driver:
Link driver
The user clicks a signed verification URL handled by:
Xul\AuthKit\Http\Controllers\Web\EmailVerification\VerifyEmailLinkControllerThat controller delegates verification to:
Xul\AuthKit\Actions\EmailVerification\VerifyEmailLinkActionToken driver
The user submits an email address and verification token handled by:
Xul\AuthKit\Http\Controllers\Api\EmailVerification\VerifyEmailTokenControllerThat controller delegates verification to:
Xul\AuthKit\Actions\EmailVerification\VerifyEmailTokenActionMiddleware Protection
Pending verification pages are protected by:
Xul\AuthKit\Http\Middleware\EnsurePendingEmailVerificationMiddlewareThis middleware validates that the current request still has a valid pending verification context.
For the link driver, it can validate:
- route
id - route
hash
For the token driver, it requires:
- a valid email context
- a pending verification presence for that email
If no valid pending context exists, AuthKit redirects to the route configured at:
authkit.route_names.web.loginValidation
Validation is handled by these request classes:
resend verification:
Xul\AuthKit\Http\Requests\EmailVerification\SendEmailVerificationRequesttoken verification:
Xul\AuthKit\Http\Requests\EmailVerification\EmailVerificationTokenRequestThese requests are driven by:
authkit.schemas.email_verification_send
authkit.schemas.email_verification_token
authkit.validation.providers.email_verification_send
authkit.validation.providers.email_verification_tokenDefault rules
For resend verification:
email→required|string|email
For token verification:
email→required|string|emailtoken→required|string
Custom validation providers
You may override default validation through:
authkit.validation.providers.email_verification_send
authkit.validation.providers.email_verification_tokenAny custom provider must implement:
Xul\AuthKit\Contracts\Validation\RulesProviderContractAuthKit resolves these providers through:
Xul\AuthKit\Support\Resolvers\RulesProviderResolverForm Schema
The UI structure for email verification is defined by:
authkit.schemas.email_verification_send
authkit.schemas.email_verification_tokenThese schemas control:
- fields
- labels
- input types
- placeholders
- wrapper metadata
- submit labels
Because the flow is schema-driven, rendering and validation remain aligned when you customize the form.
The related page controllers are:
- verification notice page:
Xul\AuthKit\Http\Controllers\Web\EmailVerification\EmailVerificationNoticeViewController- token verification page:
Xul\AuthKit\Http\Controllers\Web\EmailVerification\EmailVerificationTokenViewController- verification success page:
Xul\AuthKit\Http\Controllers\Web\EmailVerification\EmailVerificationSuccessViewControllerPayload Mapping
AuthKit maps email verification input through two mapper contexts:
email_verification_sendemail_verification_token
These are configured under:
authkit.mappers.contexts.email_verification_send
authkit.mappers.contexts.email_verification_tokenDefault resend mapper
The default resend mapper is:
Xul\AuthKit\Support\Mappers\EmailVerification\SendEmailVerificationPayloadMapperDefault behavior:
email →attributes.emailtransform→lower_trimpersist→false
Default token mapper
The default token verification mapper is:
Xul\AuthKit\Support\Mappers\EmailVerification\VerifyEmailTokenPayloadMapperDefault behavior:
email→attributes.emailtransform→ lower_trim`persist→ false`token→ attributes.token`transform→ trim`persist→ false`
Custom mappers
You may override either mapper through:
authkit.mappers.contexts.email_verification_send.class
authkit.mappers.contexts.email_verification_token.classAny custom mapper must implement:
Xul\AuthKit\Contracts\Mappers\PayloadMapperContractMapped payload building is handled through:
Xul\AuthKit\Support\Mappers\MappedPayloadBuilderResend Verification
Resend requests are handled by:
Xul\AuthKit\Http\Controllers\Api\EmailVerification\SendEmailVerificationControllerThat controller delegates to:
Xul\AuthKit\Actions\EmailVerification\SendEmailVerificationActionThe resend flow is:
- validate the request
- build the mapped payload
- resolve the user by email using the configured guard provider
- ensure the email matches the authenticated user context when applicable
- skip sending if the email is already verified
- create a new pending verification token
- dispatch
Xul\AuthKit\Events\AuthKitEmailVerificationRequired - redirect to the verification notice route
Link Verification Flow
Signed-link verification is handled by:
Xul\AuthKit\Http\Controllers\Web\EmailVerification\VerifyEmailLinkController
Xul\AuthKit\Actions\EmailVerification\VerifyEmailLinkActionThe flow is:
- extract the route id and hash
- resolve the user through the configured provider
- validate the pending link context
- consume the token from the pending verification store
- mark the user as verified
- dispatch Laravel’s
Illuminate\Auth\Events\Verifiedevent when applicable - dispatch:
Xul\AuthKit\Events\AuthKitEmailVerified - optionally log the user in
- redirect according to post-verification configuration
Token Verification Flow
Token verification is handled by:
Xul\AuthKit\Http\Controllers\Api\EmailVerification\VerifyEmailTokenController
Xul\AuthKit\Actions\EmailVerification\VerifyEmailTokenActionThe flow is:
- validate the submitted email and token
- consume the token
- resolve the user from the token payload
- ensure the submitted email matches the user email
- mark the user as verified
- dispatch
Illuminate\Auth\Events\Verifiedwhen applicable - dispatch
Xul\AuthKit\Events\AuthKitEmailVerified - optionally log the user in
- redirect according to post-verification configuration
Marking a User as Verified
Both verification actions support two common verification styles.
If the user model supports:
markEmailAsVerified()that method is used.
Otherwise, AuthKit writes to the configured verification column from:
authkit.email_verification.columns.verified_atand saves the model when supported.
This means your user model can work with Laravel’s Illuminate\Contracts\Auth\MustVerifyEmail pattern or with a simple timestamp column.
Post Verification Behavior
What happens after successful verification is controlled by:
authkit.email_verification.post_verify.mode
authkit.email_verification.post_verify.redirect_route
authkit.email_verification.post_verify.login_route
authkit.email_verification.post_verify.success_route
authkit.email_verification.post_verify.login_after_verify
authkit.email_verification.post_verify.rememberSupported modes
redirectsuccess_page
Redirect resolution
AuthKit resolves the post-verification destination in this order:
- success page when
mode = success_page - configured redirect route
- login/dashboard redirect when
login_after_verify = true - login route fallback
If automatic login after verification is enabled, AuthKit authenticates the user through the configured guard and dispatches:
Xul\AuthKit\Events\AuthKitLoggedInNotifications and Delivery Classes
AuthKit includes packaged notifications for the default mail flow:
token notification:
Xul\AuthKit\Notifications\AuthKitVerifyEmailTokenNotificationsigned link notification:
Xul\AuthKit\Notifications\AuthKitVerifyEmailLinkNotificationWhen delivery mode is queued, AuthKit can dispatch:
Xul\AuthKit\Jobs\SendEmailVerificationNotificationJobThat job also delegates to the configured notifier implementing:
Xul\AuthKit\Contracts\EmailVerificationNotifierContractEvents
AuthKit exposes two package-level events for email verification:
Verification required
Xul\AuthKit\Events\AuthKitEmailVerificationRequiredThis is dispatched when AuthKit starts a verification flow and needs delivery to occur.
Typical uses:
- sending emails
- analytics
- audit logs
- custom notification pipelines
Verification completed
Xul\AuthKit\Events\AuthKitEmailVerifiedThis is dispatched after a user has been successfully verified.
Typical uses:
- onboarding
- post-verification workflows
- analytics
- audit logs
Example Configuration
'email_verification' => [
'enabled' => true,
'driver' => 'link',
'ttl_minutes' => 30,
'columns' => [
'verified_at' => 'email_verified_at',
],
'delivery' => [
'use_listener' => true,
'listener' => \Xul\AuthKit\Listeners\SendEmailVerificationNotification::class,
'notifier' => \Xul\AuthKit\Support\Notifiers\EmailVerificationNotifier::class,
'mode' => 'sync',
'queue_connection' => null,
'queue' => null,
'delay' => 0,
],
'post_verify' => [
'mode' => 'redirect',
'redirect_route' => 'authkit.web.dashboard',
'login_route' => 'authkit.web.login',
'success_route' => 'authkit.web.email.verify.success',
'login_after_verify' => false,
'remember' => true,
],
],Overrides and Customization
You can customize the email verification flow through configuration without replacing the whole system.
Common override points include:
validation providers:
authkit.validation.providers.email_verification_send
authkit.validation.providers.email_verification_tokenpayload mappers:
authkit.mappers.contexts.email_verification_send.class
authkit.mappers.contexts.email_verification_token.classdelivery listener:
authkit.email_verification.delivery.listenernotifier:
authkit.email_verification.delivery.notifierpage and action controllers:
authkit.controllers.web.email_verify_notice
authkit.controllers.web.email_verify_token_page
authkit.controllers.web.email_verify_success
authkit.controllers.web.email_verify_link
authkit.controllers.api.email_send_verification
authkit.controllers.api.email_verify_tokenAny custom mapper must implement:
Xul\AuthKit\Contracts\Mappers\PayloadMapperContract
Any custom rules provider must implement:
Xul\AuthKit\Contracts\Validation\RulesProviderContract
Any custom notifier must implement:
Xul\AuthKit\Contracts\EmailVerificationNotifierContract
Best Practices
- Use the
linkdriver when you want the simplest browser-based verification experience. - Use the
tokendriver when you want OTP-style or API-friendly verification. - Keep:
authkit.email_verification.ttl_minutesshort enough for security. - Keep the verification column aligned with:
authkit.email_verification.columns.verified_at - Prefer customization through:
- config
- custom mappers
- custom validation providers
- custom notifier implementations
- event listeners
instead of modifying AuthKit internals directly.