User logging out automaticly

Published 10 months ago by [email protected]

I've made a few websites in Laravel but with one of them I get logged out automaticly for no reason. It just happens randomly. I checked the log files but there is nothing logged.

Does anyone have any ideas about what could be wrong?

I'm using laravel 5.2

Best Answer (As Selected By [email protected])

changing you session_driver from file to database may fix this issue.

Step 1: Edit you .env file, change SESSION_DRIVER=file to SESSION_DRIVER=database.

Step 2: create a session migration run "php artisan session:table"

Step 3: run "composer dump-autoload"

Step 4: run "php artisan migrate"


I'll try that. What I think is strange is that it sometimes happens after seconds of being logged in, sometimes after more than 15 minutes, even when I am constantly using the site. It happens while updating, deleting or even browsing from one page to another. It happend that I log in, change page and I am logged out again.


I still thinks its a session timeout problem

You can set long-time session. To do this you have to edit config/session.php and set lifetime to value you need in minutes. For example:

'lifetime' => 525600, // one year    1=1minute

After edit you have to clear config cache with command:

php artisan config:cache


Perhaps you're not logging in in the first place, try checking about what happens after a successful login. Do some dd()-ing.


I do log in. After logging in I get redirected to the admin panel with is only accessable when logged in. Usually I can move around in the admin-panel and do some changes.


I suspect a redirect happening somewhere, either in controllers or in javascript. Check your controllers and the JS files that the admin page is referencing.


JS isn't refreshing the page. Controllers all look normal, never have a logout function or redirect to logout


Probably an issue with session then.

Are you using Laravel's Auth or you made your own?


I have multiple auth. Customers use laravel's Auth, for admin I made my own.


and do you get logged out as a Customer (L5 Auth) or as an admin (your own auth)?


Check session.php and the lifetime parameter. Also check if it happens in other browsers if you've put logout on browser close.

I'm just spouting out ideas here, I can't be sure without the code.

10 months ago (926,325 XP)

Are you specifying SESSION_DOMAIN in .env or changed the same in config/session.php (session problems may be associated with this)


@Talky I get logged out as admin

@Mittensoff lifetime parameter was 120, changed it to 1200 but didn't have time to check if that changed anything. I'll do some testing right now.

What part of the code you like to see?


@Snapey I didn't, in .env it's not specified, in config/session.php it's null


Basically how you do the auth part for the admin and where you retrieve/put data in Session.


It's not browser specific. Just tested on other browser, same problem. this is my Admin Controller

class AdminAuthController extends Controller {

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

protected $redirectTo = "/webclix-admin";

public function __construct()
    $this->middleware('guest', ['except' => 'logout']);


public function showLogin(){
  return view('admin.auth.login');

protected function validator(array $data)
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',

protected function create(array $data)
    $create = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),

    $user = User::find($create->id);

     $role = Role::where('name', '=', 'client')->firstOrFail();


     return $create;


Please sign in or create an account to participate in this conversation.