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 the core endpoints and logic for registration, login, password reset, email verification, and two-factor authentication used by Laravel starter kits.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

Laravel Fortify is a highly modular, backend-agnostic authentication solution designed for Laravel applications. It excels in:

  • Decoupled architecture: Frontend-agnostic (works with SPAs, traditional Blade views, or mobile apps via API).
  • Laravel-first integration: Leverages Laravel’s built-in features (e.g., Eloquent, Sanctum, sessions) while providing customizable middleware, policies, and events.
  • Feature completeness: Covers core auth flows (registration, login, password resets, email verification, 2FA) with extensibility for custom logic (e.g., skills, passwordless auth via Features trait).
  • Security-first: Includes rate limiting, CSRF protection, and compliance with Laravel’s security best practices (e.g., password hashing, session management).

Key architectural strengths:

  • Event-driven: Emits events for critical actions (e.g., TwoFactorAuthenticationEnabled, RecoveryCodeReplaced), enabling observability and custom logic.
  • Middleware flexibility: Allows overriding default auth middleware (e.g., RedirectIfTwoFactorAuthenticatable).
  • Octane compatibility: Supports Laravel’s high-performance server (via scoped bindings in v1.35.0+).

Potential misfits:

  • Monolithic Laravel dependency: Requires Laravel’s ecosystem (e.g., Eloquent, Sanctum for SPAs). Not suitable for non-Laravel PHP projects.
  • Opinionated defaults: Assumes standard Laravel user model/table structure (though customizable via User model binding).

Integration Feasibility

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:

  • Sanctum (for SPA/API auth): Required if using frontend frameworks. Can be swapped for Passport if OAuth2 is needed.
  • Mail drivers: For email verification/resets (e.g., SMTP, Mailgun).
  • Session driver: For traditional auth (e.g., file, database, redis).

Technical Risk

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:

  1. 2FA setup: Requires google2fa package and proper database columns (two_factor_secret, two_factor_recovery_codes).
  2. Custom auth flows: Extending Fortify (e.g., adding magic links) may require deep controller/policy overrides.

Key Questions for TPM

  1. Frontend Requirements:

    • Is the frontend a SPA (React/Vue), traditional Blade app, or mobile? This dictates Sanctum/Passport choice.
    • Are there custom auth UI requirements (e.g., branded login pages) that conflict with Fortify’s defaults?
  2. User Model:

    • Does the user model extend Authenticatable and optionally TwoFactorAuthenticatable? If not, what’s the custom logic?
    • Are there non-standard auth fields (e.g., username instead of email)? Fortify’s retrieveByCredentials() may need adjustment.
  3. Security:

    • Are there compliance requirements (e.g., GDPR, SOC2) that necessitate custom event listeners or audit logging?
    • Should passwordless auth (e.g., magic links) be supported? Fortify lacks this natively (would require custom Features implementation).
  4. Scalability:

    • Will the app use Octane? If so, test scoped bindings early (v1.35.0+).
    • Is the session driver (e.g., Redis) scalable for expected user load?
  5. Migration Path:

    • Is the existing auth system (e.g., custom controllers) minimal? Fortify replaces most of it, so a big-bang migration may be needed.
    • Are there legacy auth tokens (e.g., from Laravel Passport) that need co-existence?
  6. Monitoring:

    • Should Fortify events (e.g., TwoFactorAuthenticationFailed) trigger alerts or analytics?
    • Are there custom metrics needed (e.g., 2FA success rates)?
  7. Customization:

    • Are there plans to extend Fortify (e.g., adding "skills" or custom policies)? This impacts long-term maintenance.
    • Should the default middleware (e.g., auth, verified) be renamed or customized?

Integration Approach

Stack Fit

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();

Migration Path

Option 1: Big-Bang Migration (Recommended for Greenfield Projects)

  1. Prerequisites:

    • Laravel 10+ (target v13 for latest features).
    • PHP 8.1+ (8.5 for full compatibility).
    • Configure SESSION_DRIVER (e.g., redis) and mail services.
  2. Steps:

    • Install Fortify:
      composer require laravel/fortify
      php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
      
    • Publish and configure:
      php artisan fortify:install
      
    • Update User model to implement Authenticatable (and TwoFactorAuthenticatable if using 2FA).
    • Run migrations:
      php artisan migrate
      
    • Configure frontend
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport