I want to create an api to check if the token is expired or wrong on laravel 9 but when the token is wrong the postman gave me a response with html page and ignoring my middleware that validates the response .
Asked
Active
Viewed 265 times
1 Answers
0
Since you didn't provide anything specific, I only can recommend you to look at official documentation for Laravel Sanctum especially this chapter. There you can get this piece of information:
To protect routes so that all incoming requests must be authenticated, you should attach the
sanctum
authentication guard to your protected routes within yourroutes/web.php
androutes/api.php
route files. This guard will ensure that incoming requests are authenticated as either stateful, cookie authenticated requests or contain a valid API token header if the request is from a third party.
Make sure that you use sanctum
guard with your routes, it should look like this:
use Illuminate\Http\Request;
Route::middleware('auth:sanctum')->get('/profile', function (Request $request) {
return $request->user();
});

unkownStudent
- 65
- 10