daniel-de-wit / lighthouse-sanctum

Laravel Sanctum support for Laravel Lighthouse
MIT License
57 stars 9 forks source link

Unauthenticated error #98

Closed kashy96 closed 6 months ago

kashy96 commented 1 year ago

I have recently upgraded my laravel application to 10, I am using daniel-de-wit/lighthouse-sanctum package for authentication with laravel sanctum. My login mutation works and returns the token, but for queries or mutations which need authentication I am getting unauthenticated error although authenticated. The guards inside lighthouse is null i-e 'guards' => null

daniel-de-wit commented 6 months ago

You should instruct lighthouse to use the Sanctum guard, like so:

// File: ./config/lighthouse.php
    /*
    |--------------------------------------------------------------------------
    | Authentication Guard
    |--------------------------------------------------------------------------
    |
    | The guard to use for authenticating GraphQL requests, if needed.
    | This setting is used whenever Lighthouse looks for an authenticated user, for example in directives
    | such as `@guard` and when applying the `AttemptAuthentication` middleware.
    |
    */

    'guard' => 'sanctum',