JWT authentication with Laravel & Vuejs

66 Views Asked by At

I'm working with JWT authentication using Laravel 6 and vue.js 2, and jwt package: tymon/jwt-auth. I'm testing my api using postman. But it returns "1" instead access_token. Could anyone please help me with it? Following is api method:

public function loginMe(Request $request)
{  
    
    $credentials = $request->only('email', 'password');

    try {
        if (!$token = JWTAuth::attempt($credentials)) {
            return response()->json([
                'success' => false,
                'message' => 'Login credentials are invalid.',
            ], 400);
        }
    } catch (JWTException $e) {
        return response()->json([
                'success' => false,
                'message' => 'Could not create token.',
            ], 500);
    }
    return response()->json([
        'success' => true,
        'access_token' => $token,
    ]); 
}
1

There are 1 best solutions below

1
On

Often the problem is on header.

Try to add in the Postman request, in the header:

  • Content-Type: application/x-www-form-urlencoded
  • Accept: application/json