binshops / laravel-blog

Laravel Blog Package/ Laravel CMS. Easiest way to add a blogging system to your Laravel website. Laravel Blog.
https://www.binshops.com
MIT License
422 stars 130 forks source link

404 and 401 Unauthorized #52

Closed adedejiibrahim7 closed 2 years ago

adedejiibrahim7 commented 2 years ago

I installed the package and setup everything as required. The frontend url - /en/blog returns 404. I also changed 'user_model' in the binshopsblog.php file to my admin model and added the method necessary to the model. Attempts to access the blog admin returns 401 unauthorised, even when I have an admin logged in already

Fady-Behnan commented 2 years ago

Unfortunately, it doesn't work with multiple guards. The UserCanManageBlogPosts middleware only uses the default auth guard.

class UserCanManageBlogPosts
{

    /**
     * Show 401 error if \Auth::user()->canManageBinshopsBlogPosts() == false
     * @param $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!\Auth::check()) {
            abort(401,"User not authorised to manage blog posts: You are not logged in");
            return redirect('/login');
        }
        if (!\Auth::user()->canManageBinshopsBlogPosts()) {
            abort(401,"User not authorised to manage blog posts: Your account is not authorised to edit blog posts");
        }
        return $next($request);
    }
}
shanetzulinho commented 2 years ago

I also use multiple guards. That's what I did as below: Changed Auth::user() to Auth::guard('admin')->user().