From af202d9827cfb79fd6d8db25fadd3b2466aad061 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Thu, 8 Jan 2026 15:13:15 +0100 Subject: [PATCH] Add user to shouldLink and shouldCreate oauth functions (#2083) --- app/Extensions/OAuth/OAuthSchemaInterface.php | 6 ++++-- app/Extensions/OAuth/Schemas/OAuthSchema.php | 6 ++++-- app/Http/Controllers/Auth/OAuthController.php | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Extensions/OAuth/OAuthSchemaInterface.php b/app/Extensions/OAuth/OAuthSchemaInterface.php index f050f445a..5f58a3fad 100644 --- a/app/Extensions/OAuth/OAuthSchemaInterface.php +++ b/app/Extensions/OAuth/OAuthSchemaInterface.php @@ -2,8 +2,10 @@ namespace App\Extensions\OAuth; +use App\Models\User; use Filament\Schemas\Components\Component; use Filament\Schemas\Components\Wizard\Step; +use Laravel\Socialite\Contracts\User as OAuthUser; interface OAuthSchemaInterface { @@ -33,7 +35,7 @@ interface OAuthSchemaInterface public function isEnabled(): bool; - public function shouldCreateMissingUsers(): bool; + public function shouldCreateMissingUser(OAuthUser $user): bool; - public function shouldLinkMissingUsers(): bool; + public function shouldLinkMissingUser(User $user, OAuthUser $oauthUser): bool; } diff --git a/app/Extensions/OAuth/Schemas/OAuthSchema.php b/app/Extensions/OAuth/Schemas/OAuthSchema.php index bfa5fe21f..03853f4bf 100644 --- a/app/Extensions/OAuth/Schemas/OAuthSchema.php +++ b/app/Extensions/OAuth/Schemas/OAuthSchema.php @@ -3,12 +3,14 @@ namespace App\Extensions\OAuth\Schemas; use App\Extensions\OAuth\OAuthSchemaInterface; +use App\Models\User; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Schemas\Components\Component; use Filament\Schemas\Components\Utilities\Set; use Filament\Schemas\Components\Wizard\Step; use Illuminate\Support\Str; +use Laravel\Socialite\Contracts\User as OAuthUser; abstract class OAuthSchema implements OAuthSchemaInterface { @@ -121,14 +123,14 @@ abstract class OAuthSchema implements OAuthSchemaInterface return env("OAUTH_{$id}_ENABLED", false); } - public function shouldCreateMissingUsers(): bool + public function shouldCreateMissingUser(OAuthUser $user): bool { $id = Str::upper($this->getId()); return env("OAUTH_{$id}_SHOULD_CREATE_MISSING_USERS", false); } - public function shouldLinkMissingUsers(): bool + public function shouldLinkMissingUser(User $user, OAuthUser $oauthUser): bool { $id = Str::upper($this->getId()); diff --git a/app/Http/Controllers/Auth/OAuthController.php b/app/Http/Controllers/Auth/OAuthController.php index e75798cc1..ccdc1d647 100644 --- a/app/Http/Controllers/Auth/OAuthController.php +++ b/app/Http/Controllers/Auth/OAuthController.php @@ -79,13 +79,13 @@ class OAuthController extends Controller $user = User::whereEmail($email)->first(); if ($user) { - if (!$driver->shouldLinkMissingUsers()) { + if (!$driver->shouldLinkMissingUser($user, $oauthUser)) { return $this->errorRedirect(); } $user = $this->oauthService->linkUser($user, $driver, $oauthUser); } else { - if (!$driver->shouldCreateMissingUsers()) { + if (!$driver->shouldCreateMissingUser($oauthUser)) { return $this->errorRedirect(); }