fix keeping track of the wrong instance url (for different instance/api domains)
This commit is contained in:
parent
8474dd434a
commit
3ce9dfe7d6
|
@ -33,14 +33,15 @@ module.exports = function Login({error}) {
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// check if current domain runs an instance
|
// check if current domain runs an instance
|
||||||
|
let currentDomain = window.location.origin;
|
||||||
Promise.try(() => {
|
Promise.try(() => {
|
||||||
console.log("trying", window.location.origin);
|
console.log("trying", currentDomain);
|
||||||
return dispatch(api.instance.fetch(window.location.origin));
|
return dispatch(api.instance.fetch(currentDomain));
|
||||||
}).then((json) => {
|
}).then(() => {
|
||||||
if (instanceFieldRef.current.length == 0) { // user hasn't started typing yet
|
if (instanceFieldRef.current.length == 0) { // user hasn't started typing yet
|
||||||
dispatch(setInstance(json.uri));
|
dispatch(setInstance(currentDomain));
|
||||||
instanceFieldRef.current = json.uri;
|
instanceFieldRef.current = currentDomain;
|
||||||
setInstanceField(json.uri);
|
setInstanceField(currentDomain);
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log("Current domain does not host a valid instance: ", e);
|
console.log("Current domain does not host a valid instance: ", e);
|
||||||
|
@ -48,14 +49,15 @@ module.exports = function Login({error}) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function tryInstance() {
|
function tryInstance() {
|
||||||
|
let domain = instanceFieldRef.current;
|
||||||
Promise.try(() => {
|
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
|
// TODO: clearer error messages for common errors
|
||||||
console.log(e);
|
console.log(e);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}).then((instance) => {
|
}).then(() => {
|
||||||
dispatch(setInstance(instance.uri));
|
dispatch(setInstance(domain));
|
||||||
|
|
||||||
return dispatch(api.oauth.register()).catch((e) => {
|
return dispatch(api.oauth.register()).catch((e) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
|
@ -106,7 +106,7 @@ function fetchInstance(domain) {
|
||||||
return apiCall("GET", "/api/v1/instance")(dispatch, () => fakeState);
|
return apiCall("GET", "/api/v1/instance")(dispatch, () => fakeState);
|
||||||
}).then((json) => {
|
}).then((json) => {
|
||||||
if (json && json.uri) { // TODO: validate instance json more?
|
if (json && json.uri) { // TODO: validate instance json more?
|
||||||
dispatch(setInstanceInfo([json.uri, json]));
|
dispatch(setInstanceInfo([domain, json]));
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue