-1

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 .

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
ayaashraf
  • 48
  • 4

1 Answers1

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 your routes/web.php and routes/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();
});