I am currently confused why my response JSON for token doesn't provide token code.
"token": {
"token": {
"name": "appToken",
"abilities": [
"*"
],
"tokenable_id": 1,
"tokenable_type": "App\\Models\\User",
"updated_at": "2021-08-29T17:35:00.000000Z",
"created_at": "2021-08-29T17:35:00.000000Z",
"id": 7
}
},
Here's the code for the response.
public function login()
{
if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
$user = Auth::user();
$success['token'] = $user->createToken('appToken')->accessToken;
//After successfull authentication, notice how I return json parameters
return response()->json([
'success' => true,
'token' => $success,
'user' => $user
]);
} else {
//if authentication is unsuccessfull, notice how I return json parameters
return response()->json([
'success' => false,
'message' => 'Invalid Email or Password',
], 401);
}
}
I wanted those codes for authentication: Bearer