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:
我正在使用Laravel 6和vue.js 2以及JWT包Tymon/jwt-auth进行JWT身份验证。我正在使用邮递员测试我的API。但它返回“1”,而不是ACCESS_TOKEN。有谁能帮我搬一下吗?接口方法如下:
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,
]);
}
更多回答
优秀答案推荐
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
更多回答
Already that's given but no luck.
这已经被给予了,但没有运气。
我是一名优秀的程序员,十分优秀!