# Laravel Fortify

What is Laravel Fortify?

Laravel Fortify is a backend authentication framework for Laravel applications that handles common user authentication tasks such as login, registration, password reset, and email verification. It does not include front-end scaffolding, making it suitable for SPA or custom UI integrations.

---

## Origin

Fortify was introduced to provide a backend-only authentication solution for developers who want to build custom front-end interfaces for their applications.

---

## Why is Laravel Fortify Used?

1. **Customizable Authentication**: Enables developers to implement their own UI while managing backend authentication.
2. **Comprehensive Features**: Includes authentication features like two-factor authentication and password resets.
3. **Decouples Backend and Frontend**: Works seamlessly with SPAs and API-driven applications.

---

## Best Practices

1. **Secure API Endpoints**: Use middleware to protect Fortify routes.
2. **Customize as Needed**: Modify Fortify's actions and configuration to suit your application.
3. **Use Front-End Frameworks**: Combine Fortify with Vue or React for robust authentication workflows.

---

## Example in Action

Install Fortify:

```bash
composer require laravel/fortify
php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
```

Enable Fortify in `config/app.php`:

```php
'providers' => [
    Laravel\Fortify\FortifyServiceProvider::class,
];
```

Customize authentication logic in `FortifyServiceProvider`:

```php
Fortify::authenticateUsing(function (Request $request) {
    $user = User::where('email', $request->email)->first();

    if ($user && Hash::check($request->password, $user->password)) {
        return $user;
    }
});
```

Read this definition in a browser: https://ranetrace.com/glossary/laravel-fortify
