mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
only do API checks on logged-in state
This commit is contained in:
parent
fac0e28afb
commit
02ac28e832
1 changed files with 24 additions and 24 deletions
|
@ -58,32 +58,32 @@ function App() {
|
||||||
const [ tokenChecked, setTokenChecked ] = React.useState(false);
|
const [ tokenChecked, setTokenChecked ] = React.useState(false);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
Promise.try(() => {
|
if (loginState == "login" || loginState == "callback") {
|
||||||
// Process OAUTH authorization token from URL if available
|
Promise.try(() => {
|
||||||
if (loginState == "callback") {
|
// Process OAUTH authorization token from URL if available
|
||||||
let urlParams = new URLSearchParams(window.location.search);
|
if (loginState == "callback") {
|
||||||
let code = urlParams.get("code");
|
let urlParams = new URLSearchParams(window.location.search);
|
||||||
|
let code = urlParams.get("code");
|
||||||
if (code == undefined) {
|
|
||||||
setErrorMsg(new Error("Waiting for OAUTH callback but no ?code= provided. You can try logging in again:"));
|
if (code == undefined) {
|
||||||
} else {
|
setErrorMsg(new Error("Waiting for OAUTH callback but no ?code= provided. You can try logging in again:"));
|
||||||
return dispatch(api.oauth.tokenize(code));
|
} else {
|
||||||
|
return dispatch(api.oauth.tokenize(code));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}).then(() => {
|
||||||
}).then(() => {
|
// Fetch current instance info
|
||||||
// Fetch current instance info
|
return dispatch(api.instance.fetch());
|
||||||
return dispatch(api.instance.fetch());
|
}).then(() => {
|
||||||
}).then(() => {
|
// Check currently stored auth token for validity if available
|
||||||
// Check currently stored auth token for validity if available
|
|
||||||
if (loginState == "callback" || loginState == "login") {
|
|
||||||
return dispatch(api.user.fetchAccount());
|
return dispatch(api.user.fetchAccount());
|
||||||
}
|
}).then(() => {
|
||||||
}).then(() => {
|
setTokenChecked(true);
|
||||||
setTokenChecked(true);
|
}).catch((e) => {
|
||||||
}).catch((e) => {
|
setErrorMsg(e);
|
||||||
setErrorMsg(e);
|
console.error(e.message);
|
||||||
console.error(e.message);
|
});
|
||||||
});
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
let ErrorElement = null;
|
let ErrorElement = null;
|
||||||
|
|
Loading…
Reference in a new issue