Auto-Registration
Overview
The Auto-Registration feature enables automatic account creation for users from pre-approved email domains. Instead of requiring manual user invitation or admin approval, eligible users can self-register by verifying their email address through a secure, signed link. This is particularly useful for:- Allowing employees from your company domain to self-register
- Opening registration to partner organization domains
- Providing controlled public access based on email domain
Key Features
- Domain-based eligibility: Only emails from configured domains can register
- Role assignment: Automatically assign roles based on email domain
- Email verification: Secure, time-limited signed URLs (24-hour expiration)
- Session protection: Prevents email hijacking during registration
- Duplicate prevention: Blocks registration if user already exists
Configuration
Adding Allowed Domains
Configure auto-registration domains inconfig/auth.php:
- Key: Email domain (e.g.,
'example.com') - Value: Role to assign (e.g.,
App\Enums\Role::USER->value)
Environment-Specific Configuration
For environment-specific domains, you can use.env variables:
User Flow
1. Initial Request
User attempts to login with an email that doesn’t exist:2. Pending State
The user is redirected to:3. Email Verification
The user receives an email with a signed URL that expires in 24 hours:- The link cannot be tampered with
- The link expires after 24 hours
- Only the intended recipient can use it
4. Registration Form
When clicking the link, the user sees a registration form pre-filled with their email, where they can enter:- First name
- Last name
5. Account Creation
Upon form submission:- User account is created
- Role is automatically assigned based on domain configuration
- User is logged in immediately
- Redirected to the dashboard
API Reference
AutoRegistration Service
TheInly\Core\Services\AutoRegistration\AutoRegistration service provides the following methods:
isEligible(?string $email): bool
Check if an email is eligible for auto-registration.
true if email is eligible and user doesn’t already exist
getState(?string $email): ?array
Get auto-registration state for an email address.
domain and role, or null if not eligible
invite(string $email): void
Send an auto-registration invitation email.
InvalidArgumentException if email is not eligible
userExists(string $email): bool
Check if a user already exists with the given email (case-insensitive).
Routes
The following routes are available inroutes/guest.php:
| Method | URI | Name | Controller Method |
|---|---|---|---|
| GET | /register | auto-registration.pending | show() |
| GET | /register/create | auto-registration.create | create() |
| POST | /register/create | auto-registration.store | store() |
Security Features
1. Signed URLs
Registration links use Laravel’s signed URLs with:- 24-hour expiration
- Cryptographic signatures
- Tamper detection
2. Session-Based Email Storage
The email is stored in the session during thecreate() step, not passed as a form input. This prevents attackers from:
- Modifying the email during form submission
- Creating accounts for arbitrary email addresses
3. Domain Whitelist
Only explicitly configured domains inconfig/auth.php can register. There’s no wildcard or “open registration” mode.
4. Duplicate Prevention
The system checks for existing users (case-insensitive) before allowing registration at multiple points in the flow.5. CSRF Protection
All POST requests are protected by Laravel’s CSRF middleware.Integration Points
Triggering Auto-Registration from Login
When a user attempts to login with a non-existent email, check eligibility and redirect:Custom Registration Workflows
You can extend the auto-registration flow by listening to events or adding middleware:Frontend Components
The auto-registration flow uses the following Inertia pages:auth/auto-registration-pending: Shows “check your email” messageauth/auto-registration: Shows registration form
resources/js/Pages/ directory.
Validation Rules
The registration form validates:| Field | Rules |
|---|---|
first_name | required, string, max:255 |
last_name | required, string, max:255 |
Localization
All user-facing messages support localization. Key translation strings include:"Auto-registration is not allowed.""This registration link has expired or is invalid.""Please sign in instead""Check your email""Create account""Your email is eligible for public registration.""Registration for :app"
Troubleshooting
”Auto-registration is not allowed” Error
Cause: The email domain is not configured inconfig/auth.php
Solution: Add the domain to auto_registration_domains:
“This registration link has expired or is invalid” Error
Cause: The signed URL has expired (>24 hours old) or signature is invalid Solution: Request a new registration linkUser Already Exists Error
Cause: A user with that email already exists in the system Solution: User should use the login flow insteadEmail Not Sending
Cause: Mail configuration issue Solution:- Check
config/mail.phpsettings - Verify environment variables (MAIL_MAILER, MAIL_HOST, etc.)
- Test with
php artisan tinker:
Best Practices
- Use role enums: Always use
App\Enums\Rolevalues for role assignment - Monitor registrations: Log auto-registrations for security auditing
- Set appropriate roles: Don’t give admin roles via auto-registration
- Document allowed domains: Maintain documentation of why each domain is allowed
- Regular review: Periodically review and clean up
auto_registration_domainsconfiguration - Test thoroughly: Test the full flow when adding new domains