laravel/fortify
Laravel Fortify is a frontend-agnostic authentication backend for Laravel. It provides the core endpoints and logic for registration, login, password reset, email verification, and two-factor authentication used by Laravel starter kits.
Laravel Fortify is a highly modular, backend-agnostic authentication solution designed for Laravel applications. It excels in:
Features trait).Key architectural strengths:
TwoFactorAuthenticationEnabled, RecoveryCodeReplaced), enabling observability and custom logic.RedirectIfTwoFactorAuthenticatable).Potential misfits:
User model binding).| Factor | Feasibility | Notes |
|---|---|---|
| Laravel Version | High | Supports Laravel 10–13 (as of v1.36.2). Backward-compatible with older versions. |
| Database Schema | Medium | Requires users table with specific columns (e.g., two_factor_secret, two_factor_recovery_codes). Migration helpers provided. |
| User Model | High | Works with any Eloquent model implementing Authenticatable and optionally TwoFactorAuthenticatable. |
| Frontend Agnosticism | High | API-first design; works with React, Vue, mobile apps, or Blade templates. |
| Third-Party Auth | Medium | Primarily designed for email/password. Social auth requires custom integration (e.g., via Features::enabled()). |
| Customization | High | Override controllers, policies, requests, and views. Extend via traits (e.g., InteractsWithTwoFactorState). |
Critical dependencies:
file, database, redis).| Risk Area | Severity | Mitigation |
|---|---|---|
| Schema Migration | Medium | Test migrations in staging; use --pretend flag to dry-run. |
| 2FA Implementation | Medium | Verify pragmarx/google2fa compatibility with your environment (PHP 8.5+ required for v9). |
| Rate Limiting | Low | Customize throttles via Fortify::throttleOn() if default limits are too restrictive. |
| Session Management | Medium | Ensure session driver is configured (e.g., SESSION_DRIVER=redis for scalability). |
| Custom User Models | High | Thoroughly test retrieveByCredentials() logic if using non-standard auth fields (e.g., username). |
| Octane Compatibility | Low | Use scoped bindings (enabled by default in v1.35.0+) for Octane deployments. |
| Frontend Integration | Medium | Validate API responses (e.g., 2FA JSON structure) match frontend expectations. |
Highest-risk items:
google2fa package and proper database columns (two_factor_secret, two_factor_recovery_codes).Frontend Requirements:
User Model:
Authenticatable and optionally TwoFactorAuthenticatable? If not, what’s the custom logic?username instead of email)? Fortify’s retrieveByCredentials() may need adjustment.Security:
Features implementation).Scalability:
Migration Path:
Monitoring:
TwoFactorAuthenticationFailed) trigger alerts or analytics?Customization:
auth, verified) be renamed or customized?Fortify is optimized for the following Laravel stacks:
| Component | Compatibility | Notes |
|---|---|---|
| Laravel Core | 10–13 | Tested up to Laravel 13 (v1.36.2). Backward-compatible with older versions. |
| PHP | 8.1–8.5 | PHP 8.5 support added in v1.32.1. PHP 8.0 may work but lacks some features (e.g., union types). |
| Database | Eloquent-supported | MySQL, PostgreSQL, SQLite. Requires users table with specific columns (see schema below). |
| Session | Any driver | file, database, redis, etc. Redis recommended for scalability. |
| Frontend | Agnostic | Works with Blade, SPAs (via Sanctum), or mobile apps. |
| Queues | Optional | Email verification/resets use queues if configured. |
| Caching | Optional | Rate limiting uses cache (e.g., Redis). |
| Octane | Yes | Scoped bindings enabled by default (v1.35.0+). |
Database Schema Requirements:
// Core columns (required)
Schema::table('users', function (Blueprint $table) {
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
// 2FA columns (required for 2FA)
$table->string('two_factor_secret')->nullable();
$table->string('two_factor_recovery_codes')->nullable();
$table->timestamp('two_factor_confirmed_at')->nullable();
Prerequisites:
SESSION_DRIVER (e.g., redis) and mail services.Steps:
composer require laravel/fortify
php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
php artisan fortify:install
User model to implement Authenticatable (and TwoFactorAuthenticatable if using 2FA).php artisan migrate
How can I help you explore Laravel packages today?