jwt-guard icon indicating copy to clipboard operation
jwt-guard copied to clipboard

middleware wrong!

Open tianxingxia-cn opened this issue 7 years ago • 0 comments

error:"Request must accept a json response."

public function handle($request, Closure $next, $tokenType = 'api_token', $guard = 'jwt')
    {
//        if ($request->ajax() || $request->wantsJson()) {
            if (($errors = Auth::guard($guard)->validateToken($tokenType)) === true ) {
                if (Auth::guard($guard)->tokenIsApi()) {
                    if (Auth::guard($guard)->guest()) {
                        return response()->json('Unauthorized.', 401);
                    }
                }
            } else {
                return response()->json(['error' => $errors['message']], $errors['code']);
            }
//        } else {
//            return response()->json(['error' =>'Request must accept a json response.'], 422);
//        }

        return $next($request);
    }

tianxingxia-cn avatar Dec 06 '17 12:12 tianxingxia-cn