Skip to content

Commit

Permalink
Merge pull request #35 from MozillaSocial/auto-redirect-script-patch
Browse files Browse the repository at this point in the history
Patch: load auto-redirect script as a module instead
  • Loading branch information
aaga authored Aug 16, 2023
2 parents 7107548 + 8fa0741 commit 1d53f73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
18 changes: 18 additions & 0 deletions app/javascript/packs/auto_redirect_sign-in.js
Original file line number Diff line number Diff line change
@@ -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();
});
25 changes: 5 additions & 20 deletions app/views/auth/sessions/new.html.haml
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -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'

0 comments on commit 1d53f73

Please sign in to comment.