Skip to content

Commit 49593d1

Browse files
committedJan 12, 2019
FIX: Fix registration dialog popup for 'full screen' social logins
Regression following the ember3 upgrade. In addition to fixing, this commit consolidates our social registration logic into one place, and adds tests for the behaviour.
1 parent dcdcaeb commit 49593d1

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed
 

Diff for: ‎app/assets/javascripts/authentication-complete.js.no-module.es6

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
export default {
22
name: "auth-complete",
33
after: "inject-objects",
4-
initialize() {
4+
initialize(container) {
5+
let lastAuthResult;
6+
57
if (window.location.search.indexOf("authComplete=true") !== -1) {
6-
const lastAuthResult = localStorage.getItem("lastAuthResult");
8+
// Happens when a popup social login loses connection to the parent window
9+
lastAuthResult = localStorage.getItem("lastAuthResult");
710
localStorage.removeItem("lastAuthResult");
8-
if (lastAuthResult) {
11+
} else if (document.getElementById("data-authentication")) {
12+
// Happens for full screen logins
13+
lastAuthResult = document.getElementById("data-authentication").dataset
14+
.authenticationData;
15+
}
16+
17+
if (lastAuthResult) {
18+
const router = container.lookup("router:main");
19+
router.one("didTransition", () => {
920
Ember.run.next(() =>
1021
Discourse.authenticationComplete(JSON.parse(lastAuthResult))
1122
);
12-
}
23+
});
1324
}
1425
}
1526
};

Diff for: ‎app/views/layouts/application.html.erb

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757

5858
<%- if !current_user && cookies[:authentication_data] %>
5959
<meta id="data-authentication" data-authentication-data="<%= cookies.delete(:authentication_data) %>">
60-
<%= preload_script "authentication-complete" %>
6160
<%- end %>
6261
</head>
6362

Diff for: ‎config/application.rb

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def config.database_configuration
122122
google-tag-manager.js
123123
google-universal-analytics.js
124124
preload-application-data.js
125-
authentication-complete.js
126125
print-page.js
127126
omniauth-complete.js
128127
activate-account.js
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { acceptance } from "helpers/qunit-helpers";
2+
acceptance("Auth Complete", {
3+
beforeEach() {
4+
const node = document.createElement("meta");
5+
node.dataset.authenticationData = JSON.stringify({
6+
auth_provider: "test",
7+
email: "blah@example.com"
8+
});
9+
node.id = "data-authentication";
10+
document.querySelector("head").appendChild(node);
11+
},
12+
afterEach() {
13+
document
14+
.querySelector("head")
15+
.removeChild(document.getElementById("data-authentication"));
16+
}
17+
});
18+
19+
QUnit.test("when login not required", async assert => {
20+
await visit("/");
21+
22+
assert.equal(currentPath(), "discovery.latest", "it stays on the homepage");
23+
24+
assert.ok(
25+
exists("#discourse-modal div.create-account"),
26+
"it shows the registration modal"
27+
);
28+
});
29+
30+
QUnit.test("when login required", async assert => {
31+
Discourse.SiteSettings.login_required = true;
32+
await visit("/");
33+
34+
assert.equal(currentPath(), "login", "it redirects to the login page");
35+
36+
assert.ok(
37+
exists("#discourse-modal div.create-account"),
38+
"it shows the registration modal"
39+
);
40+
});

0 commit comments

Comments
 (0)