tuandm / laravue

Admin dashboard for enterprise Laravel applications built by VueJS and Element UI https://laravue.dev
https://laravue.dev
MIT License
2.21k stars 654 forks source link

API returns 200 {'error' => 'Unauthorized'} #265

Open hovocomunicativo opened 3 years ago

hovocomunicativo commented 3 years ago

Hello, i've developed a mobile application making use of the laravue backend and API, but it happens that when I log-in in the app and make any other requests with the retrieved token, the api returns ['error' => 'Unauthorized'] with status 200. i'm not sure of what is happening and what I'm missing here but the error is thrown from middleware/authenticate.php:

public function handle($request, Closure $next, ...$guards)
    {
        if ($this->authenticate($request, $guards) === 'authentication_error') {
            return response()->json(['error' => 'Unauthorized']);
        }

        return $next($request);
    }

    protected function authenticate($request, array $guards)
    {
        if (empty($guards)) {
            $guards = [null];
        }

        foreach ($guards as $guard) {
            if ($this->auth->guard($guard)->check()) {
                return $this->auth->shouldUse($guard);
            }
        }

        return 'authentication_error';
    }

After the login at the mobile app, all requests from the normal laravue web app or even from postman are responded with this same error. Regards