Galfau Galfau - 1 year ago 350
PHP Question

Laravel 5.3 Remember me Auth issue

I have implemented a remember me login in my laravel 5.3 project, but iam running with some issues, when the user return to the page its automaticaly logged in but the custom sessions variables are not set because the session already expired.

I have my sessions lifetime to 120 and expire on close is true.

My question is: how do I check if the user is being authed via remember me token to reasign session variables? I was thinking to create a Middleware for that but i don't know if thats the correct approach.

My customs sessions variables are:

session()->get('client_id') -> int
session()->get('acl') -> array

Can anyone guide me to the right direction?

Answer Source

Check the following solution and see if it works.

Determine if the User Was Authenticated Via the Remember Cookie


Add a event Listener to EventServiceProvider

 protected $listen = [
        'Illuminate\Auth\Events\Login' => [

Generate event and handler for the listener

php artisan event:generate

Go To UpdateLoginType and edit handle method to check login type

 public function handle(Login $event)
        if (\Auth::viaRemember()) {
            //do something
        } else {
            //do something else

Make sure your pass the remember variable properly while logging in.

Question similar to this one

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download