In Laravel Jetstream, the authentication logic is handled by Fortify. You can customize the Fortify authentication logic by creating a new Fortify service provider and registering it in your config/app.php file.
Here's an example of how you can add a check for soft deleted users in the Fortify authentication logic:
- Create a new Fortify service provider by running the following command:
php artisan make:provider CustomFortifyServiceProvider
- In the
bootmethod of your new service provider, add the following code:
use Illuminate\Http\Request;
use Laravel\Fortify\Fortify;
public function boot()
{
Fortify::authenticateUsing(function (Request $request) {
$user = User::where('email', $request->email)->first();
if ($user && $user->trashed()) {
throw ValidationException::withMessages([
Fortify::username() => __('Your account has been deactivated.'),
]);
}
if ($user && Hash::check($request->password, $user->password)) {
return $user;
}
});
}
This code checks if the user exists and is soft deleted. If the user is soft deleted, it throws a validation exception with a custom message. If the user exists and the password is correct, it returns the user.
- Register your new service provider in the
providersarray in yourconfig/app.phpfile:
'providers' => [
// ...
App\Providers\CustomFortifyServiceProvider::class,
],
After completing these steps, your Fortify authentication logic will include a check for soft deleted users.