-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use authentication middleware with this plugin? #69
Comments
Hi @lucassith, You don't need to repeat yourself by adding the Try middleware instead, check the documentation for more details. So you can apply the auth middleware to the log-viewer routes with the config file like this: 'route' => [
'enabled' => true,
'attributes' => [
'prefix' => 'log-viewer',
'middleware' => ['auth'],
],
], |
@arcanedev-maroc thanks for your response. However it does not resolve my problem. log-viewer.php 'route' => [
'enabled' => env('APP_DEBUG', false),
'attributes' => [
'prefix' => 'admin/log-viewer',
'middleware' => ['globaladmin'],
],
],
use Illuminate\Contracts\Auth\Guard;
use Auth;
class GlobalAdminMiddleware
{
protected $auth;
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
public function handle($request, Closure $next)
{
if ($this->auth->guest() || !Auth::user()->is_admin) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->route('login');
}
}
if (Auth::getUser()->is_suspended) {
Auth::logout();
return redirect('/suspended');
}
return $next($request);
}
} Every time I go to the http://my.app/admin/log-viewer I am being redirected to the login and then to the main page because I am already logged in. I am global admin. Even if I use the default auth middleware I am being redirected to the login -> main page. And as I said, if I use this middleware inside my own routes it is working well. |
So, if you go to http://my.app/admin/log-viewer and you've been redirected to the login page, that means the middleware is working for the log-viewer routes. You need to check your routes and your middleware(s) because i don't have this issue with any of my projects (LogViewer in backend side => Administration with auth middleware(s) ). |
I was able to make it work. In L5.2 middleware groups were introduced. In order to make Auth work you need to use "web" group which contains session and csrf middlewares. Thank you @arcanedev-maroc for help and this great plugin. |
You're welcome 👍 |
@lucassith I have the same problem as you in L5.2, but I was fixed it when I found this issue.
'route' => [
//...
'attributes' => [
//...
'middleware' => ['web', 'auth'],
],
//...
], |
Fun fact for anybody reading this in the future - you can re-use the gate in Laravel Nova for convenience. ...
'middleware' => ['nova']
... |
not working, any one have solution ? |
Hi.
I am looking for the solution on how to authenticate user by adding middleware to the config file. I have probably the same problem as #63 has. According to the laravel docs
should be true if the user is logged in. This is working for each route in my routes.php but not if I use it with the log-viewer config.
The text was updated successfully, but these errors were encountered: