summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2024-02-14 22:49:45 +0100
committerClaire <claire.github-309c@sitedethib.com>2024-02-14 22:55:31 +0100
commit870ee80fd366c54ee2a7fc1508d7588d3fdeb878 (patch)
treeb0bd3aa841338545c4a6c27b036383f343e90799
parent76a37bd040861549757714d2c1df733feec2f3bc (diff)
Fix user creation failure handling in OAuth paths (#29207)
-rw-r--r--app/controllers/auth/omniauth_callbacks_controller.rb3
-rw-r--r--config/locales/devise.en.yml1
-rw-r--r--spec/requests/omniauth_callbacks_spec.rb4
3 files changed, 7 insertions, 1 deletions
diff --git a/app/controllers/auth/omniauth_callbacks_controller.rb b/app/controllers/auth/omniauth_callbacks_controller.rb
index 7bccac7f6ca..b8570d0bfaa 100644
--- a/app/controllers/auth/omniauth_callbacks_controller.rb
+++ b/app/controllers/auth/omniauth_callbacks_controller.rb
@@ -16,6 +16,9 @@ class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
session["devise.#{provider}_data"] = request.env['omniauth.auth']
redirect_to new_user_registration_url
end
+ rescue ActiveRecord::RecordInvalid
+ flash[:alert] = I18n.t('devise.failure.omniauth_user_creation_failure') if is_navigational_format?
+ redirect_to new_user_session_url
end
end
diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml
index eef8214817b..b7c060016c4 100644
--- a/config/locales/devise.en.yml
+++ b/config/locales/devise.en.yml
@@ -12,6 +12,7 @@ en:
last_attempt: You have one more attempt before your account is locked.
locked: Your account is locked.
not_found_in_database: Invalid %{authentication_keys} or password.
+ omniauth_user_creation_failure: Error creating an account for this identity.
pending: Your account is still under review.
timeout: Your session expired. Please login again to continue.
unauthenticated: You need to login or sign up before continuing.
diff --git a/spec/requests/omniauth_callbacks_spec.rb b/spec/requests/omniauth_callbacks_spec.rb
index 6bbe8c5a780..6381bf0667e 100644
--- a/spec/requests/omniauth_callbacks_spec.rb
+++ b/spec/requests/omniauth_callbacks_spec.rb
@@ -60,11 +60,13 @@ describe 'OmniAuth callbacks' do
end
context 'when ALLOW_UNSAFE_AUTH_PROVIDER_REATTACH is not set to true' do
- it 'does not match the existing user or create an identity' do
+ it 'does not match the existing user or create an identity, and redirects to login page' do
expect { subject }
.to not_change(User, :count)
.and not_change(Identity, :count)
.and not_change(LoginActivity, :count)
+
+ expect(response).to redirect_to(new_user_session_url)
end
end
end