From d94b4602bc2fc97915f82957e7de3e58ada7bbd2 Mon Sep 17 00:00:00 2001 From: Joel Butcher Date: Fri, 5 Jan 2024 11:27:14 +0000 Subject: [PATCH] fix: call to user on NULL on fresh login --- src/Actions/AuthenticateOAuthCallback.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Actions/AuthenticateOAuthCallback.php b/src/Actions/AuthenticateOAuthCallback.php index 415d0241..f3628120 100644 --- a/src/Actions/AuthenticateOAuthCallback.php +++ b/src/Actions/AuthenticateOAuthCallback.php @@ -52,9 +52,9 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R $previousUrl = session()->get('socialstream.previous_url'); if ( - class_exists(FortifyFeatures::class) - && FortifyFeatures::enabled(FortifyFeatures::registration()) - && ! $account + class_exists(FortifyFeatures::class) + && FortifyFeatures::enabled(FortifyFeatures::registration()) + && ! $account && ($previousUrl === route('register') || Features::hasCreateAccountOnFirstLoginFeatures()) ) { $user = Socialstream::newUserModel()->where('email', $providerAccount->getEmail())->first(); @@ -66,12 +66,17 @@ class_exists(FortifyFeatures::class) return $this->register($provider, $providerAccount); } - if (! Features::hasCreateAccountOnFirstLoginFeatures() && ! $account) { - return $this->redirectAuthFailed( - error: __('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)]) - ); + if (! $account) { + if (! Features::hasCreateAccountOnFirstLoginFeatures()) { + return $this->redirectAuthFailed( + error: __('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)]) + ); + } + + return $this->register($provider, $providerAccount); } + $user = $account->user; $this->updatesConnectedAccounts->update($user, $account, $provider, $providerAccount);