SleepingOwlAdmin/demo

Can't get auth infomation in Admin section

xcaptain opened this issue · 5 comments

http://demo.sleepingowladmin.ru/admin/contacts2

This page can be accessed without login, if that's a bug I can help work on it.

I think it's a bug,
https://github.com/LaravelRUS/SleepingOwlAdmin/blob/development/src/Providers/AdminServiceProvider.php#L65
this line executed before route, so middleware config doesn't work.

Is there any way to get the current user in admin page?

@butschster I added auth middleware to my config, it worked fine and will force redirect to login. but I still can't get current user in app/Admin/Contact.php. \Auth::user() returns null.

Show me code.

You should add auth middleware, like this

'middleware' => ['web', 'auth'],

and

AdminSection::registerModel(Post::class, function (ModelConfiguration $model) {
    // Display
    $model->onDisplay(function () {
         dd(auth()->user());
    });
})->addMenuPage(Post::class);

Thanks, I found my mistake, I was doing

AdminSection::registerModel(Post::class, function (ModelConfiguration $model) {
    // Display
    dd(auth()->user());
    $model->onDisplay(function () {

    });
})->addMenuPage(Post::class);]

so I got null