# Laravel 9 / Auth0 SDK 7 - need 2 auth guards for web vs API paths

**URL:** <https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152>\
**Category:** Get Help\
**Tags:** laravel\
**Created:** [January 13, 2023, 5:39pm UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152 "2023-01-13T17:39:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![toby5box](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toby5box/32/42637_2.png) [@toby5box](https://community.auth0.com/u/toby5box)\
**Post date:** [January 13, 2023, 5:39pm UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/1 "2023-01-13T17:39:10Z")

</div>

We use both web app auth (session) for admin and stateless (jwt) for our API

– got this working with considerable effort with Laravel 8 + Auth0 SDK v6

– we are trying to update to Laravel 9 and Auth0 SDK v7

– I have web auth (session) working but only using the default user provider implementation (Auth0 user entity)

– we need to identify users against our own local tables in both scenarios

Taking the fairly obvious approach, our auth.php has this:

```
'guards' => [
  'admin' => [
    'driver' => 'auth0',
    'provider' => 'admins'
  ],
  'api' => [
    'driver' => 'auth0',
    'provider' => 'users'
  ]
],

'providers' => [
  'admins' => [
    'driver' => 'auth0',
    'model' => App\Providers\AdminUserProvider::class
  ],
  'users' => [...],
],

```

I have a stub AdminUserProvider implementation that just does logging. It wasn’t used in our Laravel 8 Auth0 integration.

It looks like it is not being called by Auth0 in this configuration which leaves me wondering how we can customise user provider which is important to our need for two distinct authentication paths (which start with Auth0 authentication).

---

<div class="post-metadata">

**Author:** ![toby5box](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toby5box/32/42637_2.png) [@toby5box](https://community.auth0.com/u/toby5box)\
**Post date:** [January 13, 2023, 5:44pm UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/2 "2023-01-13T17:44:08Z")

</div>

I found this page, which might have the clue.

> <https://github.com/auth0/laravel-auth0/blob/main/EXAMPLES.md#creating-a-custom-user-model>

Checking.

---

<div class="post-metadata">

**Author:** ![toby5box](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toby5box/32/42637_2.png) [@toby5box](https://community.auth0.com/u/toby5box)\
**Post date:** [January 14, 2023, 12:59am UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/3 "2023-01-14T00:59:47Z")

</div>

Unfortunately I can’t get Auth0 to use my CustomUserProvider.

Config:

```
'defaults' => [
    'guard' => 'auth0' 
],

'guards' => [
  'auth0' => [
    'driver' => 'auth0',
    'provider' => 'auth0'
  ]
],

'providers' => [
  'auth0' => [
    'driver' => 'auth0',
    'model' => App\Auth\CustomUserRepository::class
  ],
],

```

```php

namespace App\Auth;

use App\Models\Admin;
use App\Models\User;

use Illuminate\Contracts\Auth\Authenticatable;

class CustomUserRepository implements \Auth0\Laravel\Contract\Auth\User\Repository
{
  /**
   * Generate a \Auth0\Laravel\Model\Stateful\User instance from an available Auth0-PHP user session.
   *
   * @param array $user an array containing the raw Auth0 user data
   */
  public function fromSession(array $user): ?Authenticatable {
    return Admin::whereEmail($user['email'])->first();
  }

  /**
   * Generate a \Auth0\Laravel\Model\Stateful\User instance from a parsed Access Token.
   *
   * @param array $user an array containing the raw Auth0 user data
   */
  public function fromAccessToken(array $user): ?Authenticatable {
    return User::whereEmail($user['email'])->first();
  }
}

```

Auth0 does not invoke this class.

Models:

```php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Auth0\Laravel\Contract\Model\Stateful\User as StatefulUser;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableUser;

class Admin implements StatefulUser, AuthenticatableUser
{
    use HasFactory, Authenticatable;
    ...

```

```php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;

use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

use Auth0\Laravel\Contract\Model\Stateless\User as StatelessUser;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableUser;

class User implements StatelessUser, AuthenticatableUser
{
	use HasFactory, Notifiable, SoftDeletes, Authenticatable;

    ...

```

---

<div class="post-metadata">

**Author:** ![toby5box](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toby5box/32/42637_2.png) [@toby5box](https://community.auth0.com/u/toby5box)\
**Post date:** [January 14, 2023, 6:26pm UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/4 "2023-01-14T18:26:47Z")

</div>

We have abandoned the Auth0 sdk update and in consequence we have abandoned the Laravel 9 update.

I believe this example is non functional: [laravel-auth0/EXAMPLES.md at main · auth0/laravel-auth0 · GitHub](https://github.com/auth0/laravel-auth0/blob/main/EXAMPLES.md) - in addition there are some minor errors in it.

I might have more confidence if it were expanded into a complete, tested application example.

---

<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:** [January 16, 2023, 7:39am UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/5 "2023-01-16T07:39:38Z")

</div>

Hey there!

So sorry for the inconvenience! Will try to get the help from the SDK maintainers. I’m gonna contact you shortly!

---

<div class="post-metadata">

**Author:** ![toby5box](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toby5box/32/42637_2.png) [@toby5box](https://community.auth0.com/u/toby5box)\
**Post date:** [January 20, 2023, 5:35pm UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/6 "2023-01-20T17:35:49Z")

</div>

Evan at Auth0 spotted the problem.

The provider class key should be `repository` not `model`; the old key was left over from previous config and our testing with multiple user models before we found Evan’s `CustomUserRepository` example.

In `auth.php` the config should look like this:

```php
    'providers' => [
      'auth0' => [
        'driver' => 'auth0',
        'repository' => App\Auth\CustomUserRepository::class
      ],
    ],

```

Thankyou Evan!

---

<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:** [January 25, 2023, 5:42am UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/7 "2023-01-25T05:42:47Z")

</div>

Thanks for sharing it with the rest of community!

---

<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:** [February 8, 2023, 5:42am UTC](https://community.auth0.com/t/laravel-9-auth0-sdk-7-need-2-auth-guards-for-web-vs-api-paths/98152/8 "2023-02-08T05:42:52Z")

</div>

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