Hello,
I am experiencing an issue with integrating Auth0 into a Laravel project that also uses FilamentPHP. I followed the instructions provided in the Auth0 Laravel documentation to set up authentication.
However, when trying to access the admin panel, I am caught in a redirect loop between the /admin
and /login
routes.
Steps to Reproduce:
- Set up a Laravel project with FilamentPHP.
- Follow the Auth0 Laravel guide to integrate Auth0.
- Attempt to access the FilamentPHP admin panel.
auth.php
(Laravel Configuration):
'guards' => [
'auth0' => [
'driver' => 'session',
'provider' => 'auth0-provider',
],
],
'providers' => [
'auth0-provider' => [
'driver' => 'auth0.provider',
// 'model' => env('AUTH_MODEL', App\Models\User::class),
'repository' => \App\Repositories\UserRepository::class,
],
],
UserRepository.php
:
<?php
namespace App\Repositories;
use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Auth0\Laravel\{UserRepositoryAbstract, UserRepositoryContract};
final class UserRepository extends UserRepositoryAbstract implements UserRepositoryContract
{
public function fromAccessToken(array $user): ?Authenticatable
{
return User::where('auth0', $user['sub'])->firstOrFail();
}
public function fromSession(array $user): ?Authenticatable
{
$userdb = User::where('email', $user['email'])->firstOrFail();
if($userdb != null && $userdb->auth0 == null) {
$userdb->auth0 = $user['sub'] ?? '';
$userdb->save();
}
return $userdb;
}
}
AdminPanelProvider.php
:
<?php
namespace App\Providers\Filament;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
...
// ->login(Login::class)
->authMiddleware([
Authenticate::class,
])
->authGuard('auth0');
}
}
Expected Behavior:
The user should be authenticated via Auth0 and redirected to the FilamentPHP admin panel.
Actual Behavior:
The user is redirected back and forth between the /admin
and /login
routes multiple times, causing an infinite loop.
Environment:
- Laravel Version: 11.9
- FilamentPHP Version: 3.2
- Auth0-Laravel Version: 7.14.0
- PHP Version: 8.2
- Operating System: win11
Additional Information:
- I have double-checked the Auth0 configuration in the
.env
file. - No specific error logs are generated, just a continuous redirect loop.
Any assistance or guidance on how to resolve this issue would be greatly appreciated.
Thank you!