A
A
Apostol632020-03-04 08:09:30
Laravel
Apostol63, 2020-03-04 08:09:30

Why is laravel authorization not saved?

Good day everyone!

I can't solve the problem for several days now. I dug everything up and nothing helped

. I have my own session driver (I need it). Sessions are written to the database

Here are the write and read methods

public function write($sessionId, $data) {

        $payload = $this->getPayload($data);

        if(!$this->exists) {
            $this->read($sessionId);
        }

        if($this->exists) {
            $this->updateSessionActivity($sessionId);
//            return true;
        } else {
            $this->saveNewSession($sessionId, $payload);
//            return true;
        }

        return $this->exists = true;

    }


        public function read($sessionId) {
        $session = $this->model->where('id', $sessionId)->get()->toArray();

        if(isset($session) && !empty($session)) {
            $this->checkTimeActivity($session[0]['last_activity']);
        }

        if($this->exists) {
            return base64_decode($session[0]['payload']);
        }
    }


The session is stored in the database. Everything is fine
. I also have my own middleware, which, if the user is not authorized, sends it to the authentication page
public function handle($request, Closure $next) {

        if(Auth::check()) {
            return 'check';
//            return $next($request);
        } else {
            return redirect()->route('myloginget');
        }
}


And now, after authentication (I use the standard loginController), when I refresh the page or try to switch to another one, the authentication is reset and redirected to the authentication page.

In loginController after auth::attempt I output Session::all() and the array shows that the user is authorized

5e5f374987bb2991542544.png

. But, as I wrote above, when you go somewhere or refresh the page, everything is reset.

What am I doing wrong or what have I overlooked?

Here are the session.php settings
'driver' => env('SESSION_DRIVER', 'customsession'),
    'lifetime' => env('SESSION_LIFETIME', 1440),
    'table' => 'sessions,
    'secure' => env('SESSION_SECURE_COOKIE', false),


Thanks in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question