From 8fa074135ebc72645c8fa718f332f5a49a858557 Mon Sep 17 00:00:00 2001 From: Ashwin Agarwal Date: Wed, 16 Aug 2023 15:35:40 -0400 Subject: [PATCH] Load auto-redirect script as a module instead --- app/javascript/packs/auto_redirect_sign-in.js | 18 +++++++++++++ app/views/auth/sessions/new.html.haml | 25 ++++--------------- 2 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 app/javascript/packs/auto_redirect_sign-in.js diff --git a/app/javascript/packs/auto_redirect_sign-in.js b/app/javascript/packs/auto_redirect_sign-in.js new file mode 100644 index 00000000000000..284f9533df7876 --- /dev/null +++ b/app/javascript/packs/auto_redirect_sign-in.js @@ -0,0 +1,18 @@ +import { sso_redirect } from '../mastodon/initial_state'; +import ready from '../mastodon/ready'; + +ready(() => { + let form = document.createElement('form'); + form.action = sso_redirect; + form.method = 'post'; + if (localStorage.getItem('mozsoc.auth_intent') === 'signup') { + let input = document.createElement('input'); + input.type = 'hidden'; + input.name = 'intent'; + input.value = 'signup'; + form.append(input); + } + localStorage.removeItem('mozsoc.auth_intent'); + document.body.append(form); + form.submit(); +}); diff --git a/app/views/auth/sessions/new.html.haml b/app/views/auth/sessions/new.html.haml index d4871bd79d9f45..d632c7b756fdba 100644 --- a/app/views/auth/sessions/new.html.haml +++ b/app/views/auth/sessions/new.html.haml @@ -1,8 +1,11 @@ - content_for :page_title do = t('auth.login') -- unless sso_redirect - - content_for :header_tags do +- content_for :header_tags do + - if sso_redirect + = render_initial_state + = javascript_pack_tag 'auto_redirect_sign-in', crossorigin: 'anonymous' + - else = render partial: 'shared/og' - unless omniauth_only? @@ -31,23 +34,5 @@ - resource_class.omniauth_providers.each do |provider| = provider_sign_in_link(provider) -- if sso_redirect - :javascript - (function() { - let form = document.createElement('form'); - form.action = '#{ sso_redirect }'; - form.method = 'post'; - if (localStorage.getItem("mozsoc.auth_intent") == 'signup') { - let input = document.createElement('input'); - input.type = 'hidden'; - input.name = 'intent'; - input.value = 'signup'; - form.append(input); - } - localStorage.removeItem('mozsoc.auth_intent'); - document.body.append(form); - form.submit(); - })(); - - unless sso_redirect .form-footer= render 'auth/shared/links'