$npx -y skills add gdarko/laravel-vue-starter --skill fortify-developmentACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Acti
| 1 | # Laravel Fortify Development |
| 2 | |
| 3 | Fortify is a headless authentication backend that provides authentication routes and controllers for Laravel applications. |
| 4 | |
| 5 | ## Documentation |
| 6 | |
| 7 | Use `search-docs` for detailed Laravel Fortify patterns and documentation. |
| 8 | |
| 9 | ## Usage |
| 10 | |
| 11 | - **Routes**: Use `list-routes` with `only_vendor: true` and `action: "Fortify"` to see all registered endpoints |
| 12 | - **Actions**: Check `app/Actions/Fortify/` for customizable business logic (user creation, password validation, etc.) |
| 13 | - **Config**: See `config/fortify.php` for all options including features, guards, rate limiters, and username field |
| 14 | - **Contracts**: Look in `Laravel\Fortify\Contracts\` for overridable response classes (`LoginResponse`, `LogoutResponse`, etc.) |
| 15 | - **Views**: All view callbacks are set in `FortifyServiceProvider::boot()` using `Fortify::loginView()`, `Fortify::registerView()`, etc. |
| 16 | |
| 17 | ## Available Features |
| 18 | |
| 19 | Enable in `config/fortify.php` features array: |
| 20 | |
| 21 | - `Features::registration()` - User registration |
| 22 | - `Features::resetPasswords()` - Password reset via email |
| 23 | - `Features::emailVerification()` - Requires User to implement `MustVerifyEmail` |
| 24 | - `Features::updateProfileInformation()` - Profile updates |
| 25 | - `Features::updatePasswords()` - Password changes |
| 26 | - `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes |
| 27 | |
| 28 | > Use `search-docs` for feature configuration options and customization patterns. |
| 29 | |
| 30 | ## Setup Workflows |
| 31 | |
| 32 | ### Two-Factor Authentication Setup |
| 33 | |
| 34 | ``` |
| 35 | - [ ] Add TwoFactorAuthenticatable trait to User model |
| 36 | - [ ] Enable feature in config/fortify.php |
| 37 | - [ ] If the `*_add_two_factor_columns_to_users_table.php` migration is missing, publish via `php artisan vendor:publish --tag=fortify-migrations` and migrate |
| 38 | - [ ] Set up view callbacks in FortifyServiceProvider |
| 39 | - [ ] Create 2FA management UI |
| 40 | - [ ] Test QR code and recovery codes |
| 41 | ``` |
| 42 | |
| 43 | > Use `search-docs` for TOTP implementation and recovery code handling patterns. |
| 44 | |
| 45 | ### Email Verification Setup |
| 46 | |
| 47 | ``` |
| 48 | - [ ] Enable emailVerification feature in config |
| 49 | - [ ] Implement MustVerifyEmail interface on User model |
| 50 | - [ ] Set up verifyEmailView callback |
| 51 | - [ ] Add verified middleware to protected routes |
| 52 | - [ ] Test verification email flow |
| 53 | ``` |
| 54 | |
| 55 | > Use `search-docs` for MustVerifyEmail implementation patterns. |
| 56 | |
| 57 | ### Password Reset Setup |
| 58 | |
| 59 | ``` |
| 60 | - [ ] Enable resetPasswords feature in config |
| 61 | - [ ] Set up requestPasswordResetLinkView callback |
| 62 | - [ ] Set up resetPasswordView callback |
| 63 | - [ ] Define password.reset named route (if views disabled) |
| 64 | - [ ] Test reset email and link flow |
| 65 | ``` |
| 66 | |
| 67 | > Use `search-docs` for custom password reset flow patterns. |
| 68 | |
| 69 | ### SPA Authentication Setup |
| 70 | |
| 71 | ``` |
| 72 | - [ ] Set 'views' => false in config/fortify.php |
| 73 | - [ ] Install and configure Laravel Sanctum for session-based SPA authentication |
| 74 | - [ ] Use the 'web' guard in config/fortify.php (required for session-based authentication) |
| 75 | - [ ] Set up CSRF token handling |
| 76 | - [ ] Test XHR authentication flows |
| 77 | ``` |
| 78 | |
| 79 | > Use `search-docs` for integration and SPA authentication patterns. |
| 80 | |
| 81 | #### Two-Factor Authentication in SPA Mode |
| 82 | |
| 83 | When `views` is set to `false`, Fortify returns JSON responses instead of redirects. |
| 84 | |
| 85 | If a user attempts to log in and two-factor authentication is enabled, the login request will return a JSON response indicating that a two-factor challenge is required: |
| 86 | |
| 87 | ```json |
| 88 | { |
| 89 | "two_factor": true |
| 90 | } |
| 91 | ``` |
| 92 | |
| 93 | ## Best Practices |
| 94 | |
| 95 | ### Custom Authentication Logic |
| 96 | |
| 97 | Override authentication behavior using `Fortify::authenticateUsing()` for custom user retrieval or `Fortify::authenticateThrough()` to customize the authentication pipeline. Override response contracts in `AppServiceProvider` for custom redirects. |
| 98 | |
| 99 | ### Registration Customization |
| 100 | |
| 101 | Modify `app/Actions/Fortify/CreateNewUser.php` to customize user creation logic, validation rules, and additional fields. |
| 102 | |
| 103 | ### Rate Limiting |
| 104 | |
| 105 | Configure via `fortify.limiters.login` in config. Default configuration throttles by username + IP combination. |
| 106 | |
| 107 | ## Key Endpoints |
| 108 | |
| 109 | | Feature |