Alexey Alshenetsky
Alexey Alshenetsky

Reputation: 45

How to make Laravel not to prolong authentication session automatically?

By default, Laravel prolongs authentication session when a user just requests any page. I am making an application where session needs to be revalidated after access token has expired, but session never expires as long as you using an application. So how to make session expire anyway, even if you use an application?

Upvotes: 1

Views: 169

Answers (2)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Maybe there is a better solution, but you could save current time on login for example:

session(['login_at' => now()]);

Then check it in middleware and logout user if user was logged in more than an hour ago:

if (session('login_at') && session('login_at')->lt(now()->subHour())) {
    auth()->logout();
    return redirect('/');
}

Upvotes: 2

Marcel Harper
Marcel Harper

Reputation: 81

I am not sure what you want to say but check the config/session.php and there you are several php session related configs which you can change.

Check the key 'lifetime'

'lifetime' => env('SESSION_LIFETIME', 120),

Upvotes: 1

Related Questions