Andreas Christodoulou
Andreas Christodoulou

Reputation: 65

Laravel Fortify - Log Events

I have a Laravel app using Fortify, which all works correctly. I want to simply log events related to authentication, being Login, Failed Password, and Logout.

How would I be able to achieve that? I can't see anything in the fortify.php config page?

Upvotes: 1

Views: 520

Answers (1)

kimsal
kimsal

Reputation: 543

For 'login' stuff, you can create a LoginResponse class which implements the LoginResponseContract

<?php
namespace App\Http\Responses;

use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;

class LoginResponse implements LoginResponseContract
{
  public function toResponse($request)
  {

and... log data from $request there.

Delete Cookies on Logout, Laravel 8.x, Fortify/Jetstream has a bit more detail on some of this (you need to bind the new response classes in FortifyServiceProvider).

I can't quite get the LogoutResponse to be useful, because by the time the request gets to the toResponse() method, it's already cleared out who was logging out.

EDIT: For logging logout, you may have to just write your own controller and create a different logout route: https://github.com/laravel/fortify/issues/405

Upvotes: 0

Related Questions