user6085744
user6085744

Reputation: 81

Filament - Can i change default authentication in filament

I wish to use filament to my new project admin dashboard.Can i change default auth table user to any other table?.A user will login using their phone number and otp.The phone number is not in user table.Also can i use apis.?

Upvotes: -1

Views: 6136

Answers (3)

jmuchiri
jmuchiri

Reputation: 392

For Filamentphp V3, there is no auth.pages.login config option. Instead, you can copy the vendor/filament/filament/src/Pages/Auth/Login.php to app/Filament/Pages.

To point to your new login class, go to app/Providers/Filament/AdminPanelProvider.php and change the ->login() to ->login(App\Filament\Pages\Login::class)

You can now modify class as needed including the authenticate method.

Upvotes: 4

Joseph Ajibodu
Joseph Ajibodu

Reputation: 1656

Yes you can.

In the auth config, create a new provider:

'admins' => [
        'driver' => 'eloquent',
        'model' => App\Models\Admin::class,
    ],

Then create a new guard that uses the new provider:

'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],

Here is my updated auth.php config:

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

        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    ],
    
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin::class,
        ],

    ],

Now I can change the authentication guard in filament AdminServiceProvider:


->authGuard('admin')

Upvotes: 4

Dede Nugroho
Dede Nugroho

Reputation: 41

I think you need to modify the value of auth.pages.login in app/config/filament.php. Just replace it with your class with custom login logic:

return [
    /*
    |--------------------------------------------------------------------------
    | Auth
    |--------------------------------------------------------------------------
    |
    | This is the configuration that Filament will use to handle authentication
    | into the admin panel.
    |
    */

    'auth' => [
        'guard' => env('FILAMENT_AUTH_GUARD', 'web'),
        'pages' => [
            'login' => \Your\Custom\LoginLogic::class,
        ],
    ],
];

Upvotes: 4

Related Questions