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. 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:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
GuardHelpers.php (where the null user is being checked)
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.