From 2ac1894292af3388aaa33327201f282fd19f6266 Mon Sep 17 00:00:00 2001 From: Jan Cernik <66427541+jancernik@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:02:17 -0300 Subject: [PATCH] FIX: Error with social logins and fullpage signup (#29761) --- .../discourse/app/controllers/login.js | 4 +- .../instance-initializers/auth-complete.js | 6 +- spec/system/social_authentication_spec.rb | 171 +++++++++--------- 3 files changed, 93 insertions(+), 88 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/login.js b/app/assets/javascripts/discourse/app/controllers/login.js index 58d9b66a969..670c201b8e5 100644 --- a/app/assets/javascripts/discourse/app/controllers/login.js +++ b/app/assets/javascripts/discourse/app/controllers/login.js @@ -219,9 +219,9 @@ export default class LoginPageController extends Controller { signup: true, }); } else { - this.router.transitionTo("signup").then((login) => { + this.router.transitionTo("signup").then((signup) => { Object.keys(createAccountProps || {}).forEach((key) => { - login.controller.set(key, createAccountProps[key]); + signup.controller.set(key, createAccountProps[key]); }); }); } diff --git a/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js b/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js index 21962bab6b5..9166bd5d19f 100644 --- a/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js +++ b/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js @@ -140,9 +140,11 @@ export default { }; if (siteSettings.experimental_full_page_login) { - router.transitionTo("signup").then((login) => { + router.transitionTo("signup").then((signup) => { + const signupController = + signup.controller || owner.lookup("controller:signup"); Object.keys(createAccountProps || {}).forEach((key) => { - login.controller.set(key, createAccountProps[key]); + signupController.set(key, createAccountProps[key]); }); }); } else { diff --git a/spec/system/social_authentication_spec.rb b/spec/system/social_authentication_spec.rb index 42a49283d44..54d8db1d49b 100644 --- a/spec/system/social_authentication_spec.rb +++ b/spec/system/social_authentication_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -shared_context "with omniauth setup" do +shared_context "with omniauth setup" do |signup_page_object, login_page_object| include OmniauthHelpers - let(:login_modal) { PageObjects::Modals::Login.new } - let(:signup_modal) { PageObjects::Modals::Signup.new } + let(:login_form) { login_page_object } + let(:signup_form) { signup_page_object } before { OmniAuth.config.test_mode = true } end -shared_examples "social authentication scenarios" do - include_context "with omniauth setup" +shared_examples "social authentication scenarios" do |signup_page_object, login_page_object| + include_context "with omniauth setup", signup_page_object, login_page_object context "when user does not exist" do context "with Facebook" do @@ -21,13 +21,12 @@ shared_examples "social authentication scenarios" do mock_facebook_auth visit("/") - login_modal.open - login_modal.click_social_button("facebook") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("facebook") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -40,13 +39,12 @@ shared_examples "social authentication scenarios" do mock_google_auth visit("/") - login_modal.open - login_modal.click_social_button("google_oauth2") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("google_oauth2") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".header-dropdown-toggle.current-user") end @@ -55,13 +53,12 @@ shared_examples "social authentication scenarios" do mock_google_auth(verified: false) visit("/") - login_modal.open - login_modal.click_social_button("google_oauth2") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("google_oauth2") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".account-created") end end @@ -75,13 +72,12 @@ shared_examples "social authentication scenarios" do mock_github_auth visit("/") - login_modal.open - login_modal.click_social_button("github") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("github") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".header-dropdown-toggle.current-user") end @@ -90,13 +86,12 @@ shared_examples "social authentication scenarios" do mock_github_auth(verified: false) visit("/") - login_modal.open - login_modal.click_social_button("github") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("github") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".account-created") end end @@ -110,14 +105,13 @@ shared_examples "social authentication scenarios" do mock_twitter_auth visit("/") - login_modal.open - login_modal.click_social_button("twitter") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - signup_modal.fill_email(OmniauthHelpers::EMAIL) - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("twitter") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + signup_form.fill_email(OmniauthHelpers::EMAIL) + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".account-created") end @@ -126,14 +120,13 @@ shared_examples "social authentication scenarios" do mock_twitter_auth(verified: false) visit("/") - login_modal.open - login_modal.click_social_button("twitter") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - signup_modal.fill_email(OmniauthHelpers::EMAIL) - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("twitter") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + signup_form.fill_email(OmniauthHelpers::EMAIL) + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".account-created") end end @@ -147,13 +140,12 @@ shared_examples "social authentication scenarios" do mock_discord_auth visit("/") - login_modal.open - login_modal.click_social_button("discord") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("discord") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -170,13 +162,12 @@ shared_examples "social authentication scenarios" do mock_linkedin_auth visit("/") - login_modal.open - login_modal.click_social_button("linkedin_oidc") - expect(signup_modal).to be_open - expect(signup_modal).to have_no_password_input - expect(signup_modal).to have_valid_username - expect(signup_modal).to have_valid_email - signup_modal.click_create_account + signup_form.open.click_social_button("linkedin_oidc") + expect(signup_form).to be_open + expect(signup_form).to have_no_password_input + expect(signup_form).to have_valid_username + expect(signup_form).to have_valid_email + signup_form.click_create_account expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -200,8 +191,7 @@ shared_examples "social authentication scenarios" do mock_facebook_auth visit("/") - login_modal.open - login_modal.click_social_button("facebook") + signup_form.open.click_social_button("facebook") expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -214,8 +204,7 @@ shared_examples "social authentication scenarios" do mock_google_auth visit("/") - login_modal.open - login_modal.click_social_button("google_oauth2") + signup_form.open.click_social_button("google_oauth2") expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -228,8 +217,7 @@ shared_examples "social authentication scenarios" do mock_github_auth visit("/") - login_modal.open - login_modal.click_social_button("github") + signup_form.open.click_social_button("github") expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -248,8 +236,7 @@ shared_examples "social authentication scenarios" do mock_twitter_auth visit("/") - login_modal.open - login_modal.click_social_button("twitter") + signup_form.open.click_social_button("twitter") expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -262,8 +249,7 @@ shared_examples "social authentication scenarios" do mock_discord_auth visit("/") - login_modal.open - login_modal.click_social_button("discord") + signup_form.open.click_social_button("discord") expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -280,8 +266,7 @@ shared_examples "social authentication scenarios" do mock_linkedin_auth visit("/") - login_modal.open - login_modal.click_social_button("linkedin_oidc") + signup_form.open.click_social_button("linkedin_oidc") expect(page).to have_css(".header-dropdown-toggle.current-user") end end @@ -290,10 +275,28 @@ end describe "Social authentication", type: :system do context "when desktop" do - include_examples "social authentication scenarios" + include_examples "social authentication scenarios", + PageObjects::Modals::Signup.new, + PageObjects::Modals::Login.new end context "when mobile", mobile: true do - include_examples "social authentication scenarios" + include_examples "social authentication scenarios", + PageObjects::Modals::Signup.new, + PageObjects::Modals::Login.new + end + + context "when fullpage desktop" do + before { SiteSetting.experimental_full_page_login = true } + include_examples "social authentication scenarios", + PageObjects::Pages::Signup.new, + PageObjects::Pages::Login.new + end + + context "when fullpage mobile", mobile: true do + before { SiteSetting.experimental_full_page_login = true } + include_examples "social authentication scenarios", + PageObjects::Pages::Signup.new, + PageObjects::Pages::Login.new end end