A platform for community discussion. Free, open, simple.
FIX: allows authentication data to be present in bootstrap (#13885)
Joffrey JAFFEUX74f0631acd4d
diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.jsindex f062d504f0e..802454bf904 100644--- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js+++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js@@ -45,6 +45,14 @@ function head(buffer, bootstrap) {buffer.push(`<meta name="theme-color" content="${bootstrap.theme_color}">`);}+ if (bootstrap.authentication_data) {+ buffer.push(+ `<meta id="data-authentication" data-authentication-data="${encode(+ bootstrap.authentication_data+ )}">`+ );+ }+let setupData = "";Object.keys(bootstrap.setup_data).forEach((sd) => {let val = bootstrap.setup_data[sd];diff --git a/app/controllers/bootstrap_controller.rb b/app/controllers/bootstrap_controller.rbindex 4f2f40af89e..7c6c5192614 100644--- a/app/controllers/bootstrap_controller.rb+++ b/app/controllers/bootstrap_controller.rb@@ -67,7 +67,8 @@ class BootstrapController < ApplicationControllertheme_html: create_theme_html,html_classes: html_classes,html_lang: html_lang,- login_path: main_app.login_path+ login_path: main_app.login_path,+ authentication_data: authentication_data}bootstrap[:extra_locales] = extra_locales if extra_locales.present?bootstrap[:csrf_token] = form_authenticity_token if current_userdiff --git a/spec/requests/bootstrap_controller_spec.rb b/spec/requests/bootstrap_controller_spec.rbindex cd61f711146..b11e09330fd 100644--- a/spec/requests/bootstrap_controller_spec.rb+++ b/spec/requests/bootstrap_controller_spec.rb@@ -81,4 +81,16 @@ describe BootstrapController doexpect(response.status).to eq(200)expect(response.parsed_body).to be_presentend++ context "authentication data is present" do+ it "returns authentication data" do+ cookie_data = 'someauthenticationdata'+ cookies['authentication_data'] = cookie_data++ get "/bootstrap.json"++ bootstrap = response.parsed_body['bootstrap']+ expect(bootstrap['authentication_data']).to eq(cookie_data)+ end+ endend