firewall icon indicating copy to clipboard operation
firewall copied to clipboard

Is it possible to return a json response on blacklisted routes?

Open n0490b opened this issue 8 years ago • 2 comments

I am using laravel as my backend and I want to block users from accessing certain routes. However, I always get a 404 page not found when I add a route to the 'redirect_to' even when I use your coming/soon example. What am I doing wrong?

config file

    'responses' => [
        'blacklist' => [
            'code' => 403, // 200 = log && notify, but keep pages rendering

            'message' => null,

            'view' => null,

            'redirect_to' => 'authorize/user',

            'abort' => false, // return abort() instead of Response::make() - disabled by default
        ],

in my api routes

Route::get('authorize/user', [
    'uses' => 'Auth\LoginController@test'
]);

Route::group(['middleware' => 'fw-block-blacklisted'], function ()
{
    
    Route::post('test/', [
        'uses' => 'LoginController@test'
    ]);
});

controller

    public function test()
    {
        return response()->json(['error' => ' An error has occurred please try again later'], 400);
    }

n0490b avatar Nov 08 '17 18:11 n0490b

Ok I just figured it out. Its using the web routes file so I moved my authorize/user route to web.php.

Route::get('authorize/user', [
    'uses' => 'Auth\LoginController@userIsBanned'
]);

Is there anyway to specify to use the api.php file?

Thanks for the package btw its great!

n0490b avatar Nov 08 '17 18:11 n0490b

@n0490b I know it's an old issue but I wanted to answer it anyway in case other people has this issue, or you still have this problem.

If you want to use the route as an API route, you just set the config to redirect to api/authorize/user Since it's an API route, Laravel is made this way to differentiate between to the two types of routes, so all API routes has the api/ prefix.

mwkcoding avatar Oct 09 '18 06:10 mwkcoding