Answer the question
In order to leave comments, you need to log in
Laravel middlaware auth:api returns HTML, why?
Good afternoon.
Please help. I tried most of the methods from the Internet, but they do not work for me.
There is API authorization through laravel passport. The registration and authorization methods work correctly and return a token.
But there is a problem with protected routes middlaware auth:api
Route of the following type works, and returns JSON data format:
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('/auth/logout', [RegisterController::class, 'logout'])->middleware('auth:api');
Answer the question
In order to leave comments, you need to log in
Content-Type : application/json
It is necessary to put
in postman instead
Accept : application/json
Content-Type
- indicates what type of content the client will send
Accept
- indicates what type of content it expects from the server
Therefore, laravel perceives the client as a browser and returns html and not json
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question