Laravel-websockets: 403 Forbidden on Laravel Serve

Created on 16 Mar 2019  路  1Comment  路  Source: beyondcode/laravel-websockets

I followed exact docs but still I am getting some weird error on my Laravel Server.
Now when I hit 127.0.0.1:8000/laravel-websockets/ I get 403 Forbidden error which I found in Authorize Class of vendor folder.
So I dd($request->user()) and it has login user data but still it gives me abort(403) error.
When I directly return $next($request); it works like charm but I am not satisfied with my solution their has to be some reason for this situation. Kindly help me out. Thank You.

class Authorize
{
    public function handle($request, $next)
    {
        return $next($request);
        //return Gate::check('viewWebSocketsDashboard', [$request->user()]) ? $next($request) : abort(403);
    }
}

Most helpful comment

By default, dashboard available only if environment is set to local. Check APP_ENV in your .env file.

If you want to access dashboard in production, you must setup Gate, which validates user permission to do this. For example, if you want to make dashboard available for all logged users, add the following to the boot method inside your AuthServiceProvider:

Gate::define('viewWebSocketsDashboard', function ($user = null) {
    return $user != null;
});

Of course, you can make additional checks inside closure.
More info in documentation

>All comments

By default, dashboard available only if environment is set to local. Check APP_ENV in your .env file.

If you want to access dashboard in production, you must setup Gate, which validates user permission to do this. For example, if you want to make dashboard available for all logged users, add the following to the boot method inside your AuthServiceProvider:

Gate::define('viewWebSocketsDashboard', function ($user = null) {
    return $user != null;
});

Of course, you can make additional checks inside closure.
More info in documentation

Was this page helpful?
0 / 5 - 0 ratings