This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/initializers/auth-complete.js.es6
David Taylor 49593d1a00 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.
2019-01-12 12:08:13 +00:00

27 lines
858 B
JavaScript

export default {
name: "auth-complete",
after: "inject-objects",
initialize(container) {
let lastAuthResult;
if (window.location.search.indexOf("authComplete=true") !== -1) {
// Happens when a popup social login loses connection to the parent window
lastAuthResult = localStorage.getItem("lastAuthResult");
localStorage.removeItem("lastAuthResult");
} else if (document.getElementById("data-authentication")) {
// Happens for full screen logins
lastAuthResult = document.getElementById("data-authentication").dataset
.authenticationData;
}
if (lastAuthResult) {
const router = container.lookup("router:main");
router.one("didTransition", () => {
Ember.run.next(() =>
Discourse.authenticationComplete(JSON.parse(lastAuthResult))
);
});
}
}
};