PHP code example of juliomotol / laravel-auth-timeout
1. Go to this page and download the library: Download juliomotol/laravel-auth-timeout library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
juliomotol / laravel-auth-timeout example snippets
return [
/**
* The session name used to identify if the user has reached the timeout time.
*/
'session' => 'last_activity_time',
/**
* The minutes of idle time before the user is logged out.
*/
'timeout' => 15,
/**
* The event that will be dispatched when a user has timed out.
*/
'event' => JulioMotol\AuthTimeout\Events\AuthTimedOut::class,
];
Route::get('/admin', [
'uses' => 'FooBarController@Foobar',
'middleware' => ['auth.timeout:custom-guard'] // Add the guard name as a parameter for the auth.timeout middleware.
]);
class FooEventListener
{
public function handle(AuthTimedOut $event)
{
$event->user;
$event->guard;
}
}
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
CheckAuthTimeout::setRedirectTo(function ($request, $guard){
return match($guard){
'custom-guard' => route('some.route'),
default => route('auth.login')
};
});
}
}
AuthTimeout::init() // Initialize the timeout session when no has been set yet.
AuthTimeout::check($guard) // Check if a user has timed out and logs them out if so.
AuthTimeout::hit() // Reset the user's timeout session.
AuthTimeout::lastActiveAt() // The last activity time of the user.
/* Somewhere in config/session.php */
'lifetime' => 15,