rainlab/user-plugin

Question about middleware response

Closed this issue · 3 comments

Hi guys, probably its not an bug, but...
AuthMiddleware provided by RainLab.User after check for Auth::check() returns Response::make...
this was not catchable, then probably is better to use \App::abort() instead for better catching with /error route.

@snipiba Thanks. This is noted. Since the logic has been implemented this way, it is probably not a good idea to change it until the next major release.

In the meantime, it would be straight forward enough for you to define your own middleware behavior, as this is quite a simple class.

<?php namespace MeAuthor\MyPlugin\Classes;

use App;
use Auth;
use Closure;

class AuthMiddleware
{
    public function handle($request, Closure $next)
    {
        if (!Auth::check()) {
            return App::abort(403);
        }

        return $next($request);
    }
}

I've made a note to review this in future versions. Cheers 🍻

not sure if this will work, when FE users are logged in thru rainlab auth middleware, then... probably... middleware used in my plugin was never reached...

It should work. The provided class is not implemented by the plugin. It is an optional utility class supplied by the plugin, in case you want to use it. Just like this class, you are free to use your own

Your middleware should be reaching since the RainLab Middleware is not implemented anywhere by default

Hope this helps