fix(dashboard-v2): fix possible race condition
This commit is contained in:
parent
c7b8c31dbb
commit
be82050b86
|
@ -19,26 +19,36 @@ const EmailConfirmationPage = ({ location }) => {
|
||||||
const [state, setState] = useState(State.Pure);
|
const [state, setState] = useState(State.Pure);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const controller = new AbortController();
|
||||||
let timer;
|
let timer;
|
||||||
|
|
||||||
async function confirm(token) {
|
async function confirm(token) {
|
||||||
try {
|
try {
|
||||||
await accountsService.get("user/confirm", { searchParams: { token } });
|
await accountsService.get("user/confirm", {
|
||||||
|
signal: controller.signal,
|
||||||
|
searchParams: { token },
|
||||||
|
});
|
||||||
|
|
||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
navigate("/");
|
navigate("/");
|
||||||
}, 3000);
|
}, 3000);
|
||||||
setState(State.Success);
|
setState(State.Success);
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
// Don't show an error message if request was aborted due to `token` changing.
|
||||||
|
if (err.code !== DOMException.ABORT_ERR) {
|
||||||
setState(State.Failure);
|
setState(State.Failure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
confirm(token);
|
confirm(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => {
|
||||||
|
controller.abort();
|
||||||
|
clearTimeout(timer);
|
||||||
|
};
|
||||||
}, [token]);
|
}, [token]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Reference in New Issue