Closed Andrewnt219 closed 3 years ago
Yea,. this is a bug.
I think it's just because how I write the submit handler:
const onSubmit = form.handleSubmit(async (data) => {
await AuthService.signInWithEmail(
data.email,
data.password,
data.keepLogIn
).catch((err) => setSubmitError(err.error_description || err.message));
loginModal.hide();
});
I should do loginModal.hide();
in a then
clause because a promise with a catch
clause won't throw an error.
Reproduce
Branch: dev
What happened
The modal is closed
Expect
Login should open and show an error message
I suspect this is because react-hook-form doesn't properly handle errors thrown in
handleSubmit
. I might have done it wrong, but their docs is not accurate. This does not handle the throw (even though their docs says so)In the other project, I handle this with mutation from react-query. SWR seems to has the same concept for mutation, but I'm not sure.