DutchCodingCompany / filament-socialite

Add OAuth login through Laravel Socialite to Filament.
MIT License
141 stars 36 forks source link

feature: allow socialite user model customization #72

Closed kykurniawan closed 4 months ago

kykurniawan commented 5 months ago

Allow socialite user model customization by passing the model class to the plugin configuration.

Example:

Customize migration to using UUID as the primary key.

return new class extends Migration
{
    public function up()
    {
        Schema::create('socialite_users', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignUuid('user_id');
            $table->string('provider');
            $table->string('provider_id');

            $table->timestamps();
            $table->softDeletes();

            $table->unique([
                'provider',
                'provider_id',
            ]);
        });
    }

    public function down()
    {
        Schema::dropIfExists('socialite_users');
    }
};

Extend the sociallite user

class SocialiteUser extends ModelsSocialiteUser
{
    use HasUuids, SoftDeletes;
}

Pass the model class in the plugin configuration

$panel->plugin(
    FilamentSocialitePlugin::make()
        ->setSocialiteUserModelClass(SocialiteUser::class)
);