LaravelRUS / SleepingOwlAdmin

🦉 Administrative interface builder for Laravel (Laravel admin)
http://sleepingowladmin.ru/
MIT License
805 stars 217 forks source link

login with db sessions doesn't work #1272

Closed eugenem closed 3 years ago

eugenem commented 3 years ago

composer.json:

        "laravel/framework": "^6.2",
        "laravelrus/sleepingowl": "dev-development",

sleeping_owl.php:

    'middleware' => ['web', 'admin'],
    'auth_provider' => 'administrators',

auth.php:

    'guards' => [
        'admin' => [
            'driver' => 'session',
            'provider' => 'administrators',
        ],
    ],

    'providers' => [
        'administrators' => [
            'driver' => 'eloquent',
            'model' => App\Models\Administrator::class,
        ],
    ],

admin.php

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Admin
{
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard('admin')->guest()) {
            if ($request->ajax() || $request->wantsJson()) {
                return response('Unauthorized.', 401);
            } else {
                return redirect()->guest('admin_auth/login');
            }
        }

        return $next($request);
    }
}

It's all working great with file sessions, but once I switch to DB sessions, I can get to the admin dashboard, and at reload, it throws me back to login.

Regular logins work fine (not to admin).

What am I missing?

daaner commented 3 years ago

The panel itself is not responsible for authorization

daaner commented 3 years ago

one of these days I will try to check your case, maybe I will help

eugenem commented 3 years ago

I've managed somehow to fix it, almost. With custom DB session handler, and some other weird stuff. Didn't understand by myself how. Now it's working more or less, but sometimes still throws me out of the admin, and hard reload gets me back. Need to debug it further...

It's probably not related to admin at all, just to non-standard guard.

eugenem commented 3 years ago

It seems to be related to service worker caching. After disabling the cache there, seems to work fine...