I don't think they're the same tokens. Can you please post at least two tokens here for two different users?
Oct 20, 2022
4
Level 1
Passport same token
Hello. This is how I implement user authentication when they login. The problem I notice is that all users are returned the same token. Is this correct?
api.php
Route::post('/v0/user/login', 'App\Http\Controllers\UserController@login');
the UserController login method is:
public function login (Request $request){
$validated = $this->validate($request, [
'cuil' => 'required',
'password' => 'required',
]);
if (Auth::attempt($validated)) {
$user = Auth::user();
$token = $user->createToken('user_token')->accessToken;
$minutes = 1440;
$timestamp = now()->addMinute($minutes);
$expires_at = date('M d, Y H:i A', strtotime($timestamp));
return response()->json([
'status' => true,
'message' => 'Login successful',
'access_token' => $token,
'token_type' => 'bearer',
'expires_at' => $expires_at
], 200);
} else {
return response()->json([
'status' => false,
'message' => 'Invalid Credentials',
], 400);
}
}
As you can see there is the lines:
$token = $user->createToken('user_token')->accessToken;
$expires_at = date('M d, Y H:i A', strtotime($timestamp));
and then it return the token (if everything is right)
return response()->json([
'status' => true,
'message' => 'Login successful',
'access_token' => $token,
'token_type' => 'bearer',
'expires_at' => $expires_at
], 200);
All users gets the same token. This is right?
Also this are the tables in the DB.
oauth_access_tokens oauth_auth_codes oauth_clients oauth_personal_access_clients oauth_refresh_tokens
Please or to participate in this conversation.