diff --git a/web/source/settings-panel/components/login.jsx b/web/source/settings-panel/components/login.jsx index 9f659bf6a..c4bebd063 100644 --- a/web/source/settings-panel/components/login.jsx +++ b/web/source/settings-panel/components/login.jsx @@ -33,14 +33,15 @@ module.exports = function Login({error}) { React.useEffect(() => { // check if current domain runs an instance + let currentDomain = window.location.origin; Promise.try(() => { - console.log("trying", window.location.origin); - return dispatch(api.instance.fetch(window.location.origin)); - }).then((json) => { + console.log("trying", currentDomain); + return dispatch(api.instance.fetch(currentDomain)); + }).then(() => { if (instanceFieldRef.current.length == 0) { // user hasn't started typing yet - dispatch(setInstance(json.uri)); - instanceFieldRef.current = json.uri; - setInstanceField(json.uri); + dispatch(setInstance(currentDomain)); + instanceFieldRef.current = currentDomain; + setInstanceField(currentDomain); } }).catch((e) => { console.log("Current domain does not host a valid instance: ", e); @@ -48,14 +49,15 @@ module.exports = function Login({error}) { }, []); function tryInstance() { + let domain = instanceFieldRef.current; Promise.try(() => { - return dispatch(api.instance.fetch(instanceFieldRef.current)).catch((e) => { + return dispatch(api.instance.fetch(domain)).catch((e) => { // TODO: clearer error messages for common errors console.log(e); throw e; }); - }).then((instance) => { - dispatch(setInstance(instance.uri)); + }).then(() => { + dispatch(setInstance(domain)); return dispatch(api.oauth.register()).catch((e) => { console.log(e); diff --git a/web/source/settings-panel/lib/api/index.js b/web/source/settings-panel/lib/api/index.js index fa5279eb3..23aa07a96 100644 --- a/web/source/settings-panel/lib/api/index.js +++ b/web/source/settings-panel/lib/api/index.js @@ -106,7 +106,7 @@ function fetchInstance(domain) { return apiCall("GET", "/api/v1/instance")(dispatch, () => fakeState); }).then((json) => { if (json && json.uri) { // TODO: validate instance json more? - dispatch(setInstanceInfo([json.uri, json])); + dispatch(setInstanceInfo([domain, json])); return json; } });