Laravel keeps missing the session

Asked

Viewed 454 times

0

Hello

I have a system developed in Laravel 5.6 that keeps missing the session

When I log in:

private $prefix = '';
public function __construct(){
    $this->prefix = env('APP_NAME')."_";
}

Session::put([
      $this->prefix.'login' =>  $login,
      $this->prefix.'id'    =>  $user->usua_id
   ]);

This passage $this->prefix = env('APP_NAME')."_"; is to get the system name. Why?

Because I use the same system to visualize in values in simulation and not give session conflict I do the concatenation with the environment variable .env, then has directed to the production database and another to read data in simulation

Em produção    

APP_NAME=SISTEMA

Em simulação

APP_NAME=SISTEMA_TEST

The system keeps making queries every 3 seconds in the database and it seems that after some time consulting (type 5 minutes, and I scheduled to expire the session in 24horas) it simply gives error 419

Even in pages where it is not necessary to log in he loses the session

I’m performing the configuration of my ajax like this:

      $.ajaxSetup({
            headers: {'x-csrf-token': $('meta[name="csrf-token"]').attr('content')}
        })
        $.ajax({
            url: '{{ route('reader.readerList') }}',
            type: 'get',
            dataType: 'json',            
        }).done( data => {

       }

In the meta of my template page is like this:

<meta name="csrf-token" content="{{ csrf_token() }}">

How can I solve this problem?

  • Check the 'Lifetime' of your session in config/Session.php

  • It’s set for 1140, two days

  • Well, the answer is strange, but: define your session.php for database instead of file

  • I won’t need to set up a database ?

1 answer

0

This was happening to me when I put in some link the command Auth::logout(), example:

<a href="{{ Auth::logout() }}">Sair</a>

If this is happening, the ideal would be to remove this command from an application link and place it inside some route directly or inside some controller accessed by a route, for example:

<a href="{{ route('logout') }}">Sair</a>

Web.php route file:

Route::get('logout', function () { Auth::logout(); });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.