# Basic Auth0 auth guard not working in Laravel

**URL:** <https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [July 13, 2023, 11:05am UTC](https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187 "2023-07-13T11:05:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrhilldev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jrhilldev/32/48848_2.png) [@jrhilldev](https://community.auth0.com/u/jrhilldev)\
**Post date:** [July 13, 2023, 11:05am UTC](https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187/1 "2023-07-13T11:05:07Z")

</div>

Hello,

I have an existing laravel installation which uses Auth0. It previously has used auth0/login ^6 but I have upgraded as part of my migration from Laravel 8 to 9. As per the auth0 docs, auth0/login ^7 uses the laravel default auth guard. So you just use -\>middleware(‘auth’) on your routes etc and it should work providing you have configured you application properly. I have downloaded the sample auth0 laravel application from here [GitHub - auth0-samples/laravel: Laravel 9 application demonstrating Auth0 integration, using the Auth0 Laravel SDK.](https://github.com/auth0-samples/laravel) and configured my application to mirror exactly what i see in this application.

Now when I attempt to access a route which uses the auth middleware I get 401 ‘Unauthenticated.’. This is because the user is null when checked by the auth guard at this point.  
auth.php:

```auto
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    ],

```

```auto
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        // 'users' => [
        // 'driver' => 'database',
        // 'table' => 'users',
        // ],
    ],

```

GuardHelpers.php (where the null user is being checked)

```auto
    public function check()
    {
        return ! is_null($this->user());
    }

```

All my .env vars seem to be in order. I don’t think it has anything to do with that.  
Is there an auth0 guard I need to use on my routes maybe? Do I have to add any auth0 specific config into auth.php? The docs suggest that auth0/login ^7 does not need anything in these files and that it should simply integrate with the existing laravel auth guard. Any Ideas?

Thanks.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 14, 2023, 10:25am UTC](https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187/2 "2023-07-14T10:25:21Z")

</div>

Hey there!

@evansims would you be able to help us on this one here? Thank you!

---

<div class="post-metadata">

**Author:** ![evansims](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evansims/32/27011_2.png) [@evansims](https://community.auth0.com/u/evansims)\
**Post date:** [July 17, 2023, 5:55am UTC](https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187/3 "2023-07-17T05:55:06Z")

</div>

Hi @jrhilldev 👋 Thanks for your question, and sorry to hear you’re hitting challenges.

> As per the auth0 docs, auth0/login ^7 uses the laravel default auth guard.

This refers to Laravel’s native `auth` middleware, which lives at `app\HTTP\Middleware\Authentication.php` within your application, rather than a guard.

> I have downloaded the sample auth0 laravel application from here GitHub - auth0-samples/laravel: Laravel 9 application demonstrating Auth0 integration, using the Auth0 Laravel SDK. and configured my application to mirror exactly what i see in this application.

Does the sample application work “out of the box” for you?

> Now when I attempt to access a route which uses the auth middleware I get 401 ‘Unauthenticated.’.

Are you accessing routes in the `web` or `api` middleware/route groups?

If you are receiving 401s, I would expect you to be hitting `api` endpoints, which would require a bearer token to be provided. If this is the case, are you providing a bearer token with your requests?

> GuardHelpers.php (where the null user is being checked)

This should never be firing, as the Laravel SDK does not use the `GuardHelpers` trait. This would tell me your application’s routes are not invoking the SDK’s authentication guards.

> Is there an auth0 guard I need to use on my routes maybe?

These guards are automatically installed by the SDK at application boot time, unless [configured otherwise](https://github.com/auth0/laravel-auth0/blob/main/docs/Configuration.md#guard-registration).

> Do I have to add any auth0 specific config into auth.php?

You do not need anything in the `auth.php` file unique or configured for the SDK.

However, you should have a `config/auth0.php` file present in your application. If this is not there, please ensure you’ve followed all the installation steps of the SDK outlined in the README, as you may need to [generate the SDK configuration file.](https://github.com/auth0/laravel-auth0/blob/main/README.md#1-install-the-sdk)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 17, 2023, 6:32am UTC](https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187/4 "2023-07-17T06:32:16Z")

</div>

Thank you a lot for your help @evansims ! 🙏

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 31, 2023, 6:32am UTC](https://community.auth0.com/t/basic-auth0-auth-guard-not-working-in-laravel/111187/5 "2023-07-31T06:32:25Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
