I'm no sure, but, try to add a Header to your request: Accept: application/json
Laravel Sanctum API Login
So I have finally decided to use Laravel 8 with fortify/sanctum. But I am a bit confused as to why the default API route is redirecting me to the login page instead of showing me a message like "unauthenticated"
I have a custom login/register controller which simply registers or logs in the user and creates a new token using the $user->createToken('user-token'). But now when I try to go to this route:
Route::middleware('auth:sanctum')->get('index', [\App\Http\Controllers\TestController::class, 'index']);
in postman, it shows me the login page. How do I show the unauthenticated message? What am I doing wrong? By default, arent api routes supposed to authenticate with tokens and show unauthenticated if failed?
I actually figured out what the issue was. In the Authenticate middleware, we have a method which redirects the user to login if attempt fails. So I just changed the redirect method or override it somewhere else
Please or to participate in this conversation.