laravel/fortify
Frontend-agnostic authentication backend for Laravel. Provides endpoints and services for registration, login, password reset, email verification, and two-factor authentication. Used by Laravel Starter Kits; you bring the UI (Blade, Inertia, SPA, etc.).
Laravel Fortify is a highly specialized, opinionated authentication backend designed for Laravel applications. It excels in:
Key Fit Criteria: ✅ Ideal for: Greenfield Laravel projects, SPAs needing backend auth, or teams prioritizing security and rapid development. ❌ Less ideal for: Legacy systems with deeply custom auth logic or non-Laravel stacks.
Fortify’s integration hinges on three pillars:
Laravel Compatibility:
users table (or custom models) with minimal schema requirements (e.g., two_factor_secret for 2FA).LoginController).Frontend Agnosticism:
POST /login returns a token), but can be adapted for hybrid setups.Security Features:
pragmarx/google2fa package.Feasibility Risks:
VerifyCsrfToken and EnsureEmailIsVerified middleware may clash with existing middleware.User contract or configuring custom providers.| Risk Area | Severity | Mitigation |
|---|---|---|
| Version Lock-in | Medium | Fortify evolves with Laravel; breaking changes are rare but require updates. |
| SPA-Specific Quirks | High | Sanctum misconfigurations (e.g., CORS, token expiry) can break auth flows. |
| 2FA Implementation | Medium | Requires pragmarx/google2fa; database schema must support two_factor_secret. |
| Passkey Support | Low | New in v1.37.0; may need additional browser/OS support testing. |
| Customization Overhead | Low | Fortify’s policies/controllers can be overridden, but deep customization may require forking. |
| Performance | Low | Minimal overhead; rate limiting and encryption are optimized. |
Critical Questions for TPM:
Fortify is optimized for the following Laravel stacks:
Non-Fit Scenarios:
| Phase | Steps | Tools/Commands |
|---|---|---|
| Prerequisites | Ensure Laravel 11+ and PHP 8.2+. Update dependencies (composer.json). |
composer require laravel/fortify |
| Installation | Publish Fortify’s config/views and run migrations (if using custom user model). | php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider" |
| Configuration | Configure fortify.php for guards, user model, and frontend (SPA/Blade). |
Edit config/fortify.php |
| Route Overrides | Replace existing auth routes (e.g., Auth::routes()) with Fortify’s registered routes. |
Remove Auth::routes() from routes/web.php |
| Middleware | Ensure VerifyCsrfToken, EnsureEmailIsVerified, and RedirectIfAuthenticated are correctly applied. |
Check app/Http/Kernel.php |
| Frontend Setup | For SPAs: Install Sanctum and configure CORS. For Blade: Use Fortify’s views or custom templates. | composer require laravel/sanctum |
| Testing | Test all auth flows (registration, login, 2FA, password resets) in staging. | Laravel’s php artisan test |
| Deployment | Deploy with database migrations (if applicable) and cache configuration. | php artisan migrate --force |
Rollback Plan:
config/app.php.| Component | Compatibility Notes |
|---|---|
| Laravel Versions | Officially supports Laravel 11–13 (as of v1.37.x). Laravel 10 requires v1.34.x or lower. |
| PHP Versions | PHP 8.2+ (PHP 8.1 dropped in v1.37.0). PHP 8.5+ requires v1.32.1+. |
| Database | Works with any Eloquent-supported database. Custom user models require FortifyUser contract implementation. |
| Frontend Frameworks | Agnostic; works with any framework that can make HTTP requests (SPAs, mobile apps, etc.). |
| Third-Party Packages | Conflicts possible with packages that override Auth or Route services (e.g., custom auth middleware). |
| Octane | Compatible via scoped bindings (added in v1.35.0). |
Key Compatibility Checks:
composer why-not laravel/fortify to detect version conflicts.php artisan fortify:check (if available) or manually verify route/middleware conflicts.Recommended integration sequence for minimal disruption:
composer.json and publish assets.guard in fortify.php to match your user model.How can I help you explore Laravel packages today?