Laravel - LoginController::authenticated() not fired at each login?

Related searches

I'm trying to log the IP address and login timestamps when users log into our system, and in order to do so I have overriden the authenticated() method of the LoginController :

function authenticated(Request $request, $user) {
      $user->update([
        'last_login_at' => Carbon::now(),
        'last_ip' => $request->getClientIp()
      ]);
    }

The strange thing is that I can see in the database that the last login from some users are several days ago, whether I know for a fact that they performed actions on the website today (while being logged-in), as shown by other logs..

Is there a possibility that authenticated() is not being fired, depending on how the user logs in?

Laravel, I'm trying to log the IP address and login timestamps when users log into our system, and in order to do so I have overriden the authenticated()� I have created a new Laravel 5.2 installation. And I have run the following command to install the default Laravel authentication; php artisan make:auth The registration form works but the login

It seems okay only thing you missed maybe the return statement? In my application I have similar functionality and working fine try below -

protected function authenticated(Request $request, $user) {

    $user->last_login_at = Carbon::now();
    $user->last_ip = $request->getClientIp();
    $user->save();

    return redirect()->intended($this->redirectPath());
}

Authentication, For many applications, you will not need to modify these controllers at all. attempt is successful and the user is logged in, the auth.login event will be fired as well. if (Auth::user()) { // Auth::user() returns an instance of the authenticated user. When we login in with proper details, the login logic is fired and completed properly, but after that its just redirected back to the login page, so is likely that the middleware thinks that the user is not logged in and returns them to the login page, that is why we think is has something to do with the sessions.

Not sure how your system is set-up but you can always try listening for the Login event which is fired whenever a user logs in via any means. This includes getting authenticated after the session is expired and the user is automatically logged in via the "remember me" cookie.

In your EventServiceProvider you can add:

\Event::listen(\Illuminate\Auth\Events\Login::class, function ($event) {
      $event->user->update([
         'last_login_at' => Carbon::now(),
         'last_ip' => request()->getClientIp()
     ]);
});

Note if your session does not actually expire or lasts a very long time users might stay logged in for a very long time.

Route to Auth\LoginController@action not working, But when using action in LoginController, the following is not working In LoginController, I just dd and the action is not called because the output is always the one of the /home route. \App\Http\Middleware\ RedirectIfAuthenticated::class use AuthenticatesUsers; /** * Where to redirect users after login. In this case, the RateLimiter resets the user’s login attempts to give them a clean slate and avoid throttling based on stale attempts. Of course, if true is returned from the tooManyAttempts method, the user isn’t allowed to login, and Laravel responds accordingly. First, a new Lockout event is fired using Laravel’s event system. After

Login Event, However the event does not get fired unless I manually fire it i.e. adding event( new to an overridden authenticated function in the LoginController will cause the even to fire but leaving as per. https://laravel.com/docs/5.7/authentication# events @return void */ public function boot() { parent::boot(); // } }. The Login event contains the authenticated User, the Guard name being used, and if the user is set to be remembered by a stateful mechanism (like cookies). The OtherDeviceLogout is an optional

Laravel Impersonate is a plugin that allows you to authenticate as your users. - 404labfr/laravel-impersonate

cleanup: boolean, default true - all database queries will be run in a transaction, which will be rolled back at the end of each test. run_database_migrations: boolean, default false - run database migrations before each test. database_migrations_path: string, default null - path to the database migrations, relative to the root of the application.

Comments
  • Thanks.. no luck here though.. The attributes are fillable (they do get filled sometimes, but not everytime it seems) - and "remember me" is disabled on my system