Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fortify Laravel Package

laravel/fortify

Laravel Fortify is a frontend-agnostic authentication backend for Laravel. It provides registration, login, password reset, email verification, and two-factor authentication endpoints and features used by Laravel starter kits, while letting you build your own UI.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Native Integration: Fortify is purpose-built for Laravel, leveraging its core authentication stack (e.g., Eloquent models, middleware, and Sanctum/Passport for APIs). This ensures seamless alignment with Laravel’s architecture, reducing friction in authentication workflows (e.g., sessions, cookies, and CSRF protection).
  • Frontend Agnostic: Designed to work with any frontend (SPAs, traditional Blade views, or mobile apps), making it ideal for modern full-stack or decoupled architectures.
  • Modular Design: Components like Features, Rules, and Traits (e.g., InteractsWithTwoFactorState) allow granular customization without monolithic overrides. Example: Extending Features to toggle password resets or 2FA dynamically.
  • Event-Driven: Emits events (e.g., TwoFactorAuthenticationEnabled, RecoveryCodeReplaced) for observability and extensibility, enabling integration with third-party services (e.g., analytics, audit logs).

Integration Feasibility

  • Low-Coupling: Fortify replaces or augments Laravel’s default Auth scaffolding (e.g., LoginController, RegisterController) without requiring changes to existing business logic. Example: Swap Auth::attempt() with Fortify’s AttemptToAuthenticate trait.
  • API-First Ready: Works out-of-the-box with Sanctum/Passport for token-based auth, critical for SPAs or mobile apps. Supports JSON responses natively (e.g., JsonResponse for 2FA flows).
  • Database Agnostic: Uses Eloquent’s query builder, so it adapts to any database schema (MySQL, PostgreSQL, SQLite) as long as the users table follows Laravel conventions.
  • Middleware Integration: Provides built-in middleware (e.g., EnsureEmailIsVerified, RedirectIfTwoFactorAuthenticatable) for route protection, reducing boilerplate.

Technical Risk

  • Version Lock-In: Fortify’s rapid evolution (e.g., PHP 8.1 dropped in v1.37.0) may require proactive dependency updates. Risk mitigation: Pin versions in composer.json and monitor Laravel’s release schedule.
  • Customization Complexity: Overriding default behaviors (e.g., password policies, 2FA logic) may require deep trait/middleware understanding. Example: Extending UpdateUserPassword to enforce org-specific rules.
  • Passkey Support: New in v1.37.0, passkeys introduce browser/OS-specific quirks (e.g., WebAuthn compatibility). Test thoroughly in target environments.
  • Session Handling: Fortify regenerates sessions on registration (v1.31.0), which may conflict with existing session management (e.g., shared sessions across subdomains). Validate with session()->regenerate().

Key Questions

  1. Frontend Compatibility:
    • Is the frontend a SPA (React/Vue), traditional Blade app, or mobile? Fortify’s SPA mode requires Sanctum/Passport config; Blade apps may need view adjustments.
  2. Existing Auth Stack:
    • Does the app use custom auth logic (e.g., LDAP, OAuth)? Fortify’s UserProvider can be extended, but conflicts may arise with non-Eloquent providers.
  3. 2FA Requirements:
    • Are hardware tokens (YubiKey) or TOTP (Google Authenticator) needed? Fortify supports both but may need middleware tweaks for custom recovery codes.
  4. Performance:
    • Will session regeneration (v1.31.0) impact high-traffic routes? Benchmark with laravel-debugbar or Blackfire.
  5. Compliance:
    • Does the app require GDPR/CCPA features (e.g., password visibility, audit logs)? Fortify’s events enable logging, but custom logic may be needed for data exports.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Fortify is optimized for Laravel 10/11/12/13, with PHP 8.2+ support. Key integrations:
    • Sanctum/Passport: For API token auth (SPAs/mobile).
    • Jetstream/Breeze: If using these starter kits, Fortify is the underlying auth layer.
    • Horizon/Queues: Fortify’s email verification uses queues; ensure mail driver is configured.
    • Octane: Compatible via scoped bindings (v1.35.0).
  • Database: Requires users table with email_verified_at, two_factor_secret, and two_factor_recovery_codes columns. Migrations are provided.
  • Frontend:
    • SPAs: Use Sanctum + Fortify’s JSON endpoints (e.g., /sanctum/csrf-cookie).
    • Blade: Leverage Fortify’s views (optional) or build custom forms using its controllers.

Migration Path

  1. Assessment Phase:
    • Audit existing auth logic (e.g., Auth::attempt(), custom guards). Identify conflicts with Fortify’s UserProvider.
    • Check for hardcoded routes (e.g., /login). Fortify uses named routes (fortify.login).
  2. Dependency Setup:
    composer require laravel/fortify
    php artisan fortify:install
    
    • This publishes config (config/fortify.php), migrations, and views.
  3. Configuration:
    • Update config/fortify.php for:
      • Email verification (e.g., features.email_verification).
      • 2FA (e.g., two_factor_authentication).
      • Password policies (e.g., password_length).
    • Configure Sanctum/Passport if using APIs:
      Fortify::useSanctum();
      // or
      Fortify::usePassport();
      
  4. Route Replacement:
    • Replace default auth routes (Auth::routes()) with Fortify’s:
      Route::middleware('guest')->group(function () {
          Route::get('/login', [Action::class, 'showLoginForm']);
          Route::post('/login', [Action::class, 'store']);
          // ... other routes
      });
      
  5. Testing:
    • Validate all auth flows:
      • Registration, login, logout.
      • Email verification (check verified_user middleware).
      • 2FA (TOTP/passkeys).
      • Password resets.
    • Test edge cases: Rate limiting (throttle), session fixation, CSRF.

Compatibility

  • Laravel Versions: Fortify v1.x supports Laravel 10–13. Drop PHP 8.1 support in v1.37.0.
  • Custom Auth: If using non-Eloquent providers (e.g., DatabaseUserProvider), extend FortifyUserProvider or override retrieveByCredentials().
  • Third-Party Packages: Potential conflicts with packages modifying Auth or session logic (e.g., spatie/laravel-permission). Test with php artisan package:discover.
  • Legacy Code: Fortify’s Features class allows toggling functionality (e.g., disable password resets):
    Fortify::disablePasswordResets();
    

Sequencing

  1. Phase 1: Core Auth (2–3 sprints):
    • Replace Auth scaffolding with Fortify.
    • Implement registration/login flows.
    • Test session handling and CSRF.
  2. Phase 2: Advanced Features (1–2 sprints):
    • Enable 2FA (TOTP/passkeys).
    • Configure email verification.
    • Set up password policies.
  3. Phase 3: API Integration (1 sprint):
    • Configure Sanctum/Passport.
    • Test token-based auth flows.
  4. Phase 4: Customization (Ongoing):
    • Extend traits (e.g., UpdateUserProfileInformation).
    • Add custom middleware (e.g., org-specific auth rules).
    • Integrate with monitoring (e.g., log TwoFactorAuthenticationEnabled events).

Operational Impact

Maintenance

  • Dependency Updates: Fortify’s active development (monthly releases) requires regular updates. Use composer why-not laravel/fortify to track breaking changes.
  • Configuration Drift: Centralize Fortify settings in config/fortify.php to avoid hardcoded values across controllers.
  • Custom Logic: Document overrides (e.g., extended Features or Rules) in a CONTRIBUTING.md section to aid future maintainers.
  • Security Patches: Monitor Laravel’s security releases and update Fortify proactively (e.g., passkey vulnerabilities).

Support

  • Debugging:
    • Use php artisan fortify:check to validate setup.
    • Enable debug mode (config/fortify.php['debug'] = true) for verbose error messages.
    • Leverage Laravel’s debugbar to inspect auth events (e.g., Authenticating).
  • Common Issues:
    • 2FA Failures: Verify `
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony