I am trying to create an API with Laravel passport, and I have to protect some routes so that only authenticated users can access these routes.
Route::post('register', [ApiAuthController::class, 'register']);
Route::post('login', [ApiAuthController::class, 'login']);
Route::middleware('auth:api')->group(function () {
Route::post('/task', [ApiControllerTaskController::class,'store']);
});
Now hereafter login, I got an access token, and I used this access token like this.
Everything is working fine here, but I want to show an invalid token error message when I removed the bearer token. Instead, I got this.
Make sure you added the Content-type
: application/json
in your headers in Postman before sending your request