Skip to content

Instantly share code, notes, and snippets.

@tomaserlebach
Last active April 4, 2022 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaserlebach/7851158b4c212270146d99cda81c7971 to your computer and use it in GitHub Desktop.
Save tomaserlebach/7851158b4c212270146d99cda81c7971 to your computer and use it in GitHub Desktop.
Fix Laravel API returns 401 on axios request

If you are using axios inside Inertia and you are running into 401 responses when trying to make axios requests on a Laravel API you should check your app/Http/Kernel.php.

Ensure that the Class EnsureFrontendRequestsAreStateful is not commented out.

app/Http/Kernel.php:

        'api' => [
            \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment