I am using laravel 5.5 with passport authentication for API Routes. I am using bearer token. The problem is that the old generated token is accepted in place of unauthenticated. Steps :
Is there any way by what I can achieve this? Thanks in advance.
One possible solution is: Check before creating a new token, if an old one is existing and delete this one. To do this:
Create a Model named OauthAccessToken
Update your User Model the following
/**
* 1:n zu access token, we need to logout users
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function accessTokens()
{
return $this->hasMany(OauthAccessToken::class);
}
Now you can check with this and delete all tokens from a user
if ($user->accessTokens->count() > 0) {
$user->accessTokens()->delete();
}