fix(frontend): fix discord login page
This commit is contained in:
parent
493c0963d5
commit
0c4f97b3cc
1 changed files with 15 additions and 12 deletions
|
@ -50,13 +50,20 @@ export default function Discord() {
|
||||||
}>({ username: "", invite: "" });
|
}>({ username: "", invite: "" });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!router.query.code || !router.query.state) {
|
if (state.isLoading || !router.query.code || !router.query.state) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!state.ticket && !state.token) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we got a token + user, save it and return to the home page
|
||||||
|
if (state.token) {
|
||||||
|
window.localStorage.setItem("pronouns-token", state.token);
|
||||||
|
setUser(state.user!);
|
||||||
|
|
||||||
|
router.push("/");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState({ ...state, isLoading: true });
|
||||||
fetchAPI<CallbackResponse>("/auth/discord/callback", "POST", {
|
fetchAPI<CallbackResponse>("/auth/discord/callback", "POST", {
|
||||||
callback_domain: window.location.origin,
|
callback_domain: window.location.origin,
|
||||||
code: router.query.code,
|
code: router.query.code,
|
||||||
|
@ -86,16 +93,12 @@ export default function Discord() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// we got a token + user, save it and return to the home page
|
if (!state.ticket && !state.token) {
|
||||||
if (state.token) {
|
return;
|
||||||
window.localStorage.setItem("pronouns-token", state.token);
|
|
||||||
setUser(state.user!);
|
|
||||||
|
|
||||||
router.push("/");
|
|
||||||
}
|
}
|
||||||
}, [state.token, state.user, setState, router]);
|
}, [router.query.code, router.query.state, state.token]);
|
||||||
|
|
||||||
if (!state.ticket && !state.error) {
|
if (state.isLoading || (!state.ticket && !state.error)) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
} else if (!state.ticket && state.error) {
|
} else if (!state.ticket && state.error) {
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue