From: ayan4m1 Date: Fri, 16 Jun 2023 14:03:31 +0000 (-0400) Subject: handle login failures correctly X-Git-Url: http://these/git/%22/display/44b525e5-4101b003e005e70a-d472d963/static/%7Bthis.state.post.url%7D?a=commitdiff_plain;h=93e359832895e9bf3662e3511fbf4b74ade57f8c;p=lemmy-ui.git handle login failures correctly --- diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index 3ddb4bc..841a3d2 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -160,42 +160,38 @@ export class Login extends Component { if (username_or_email && password) { i.setState({ loginRes: { state: "loading" } }); - try { - const loginRes = await HttpService.client.login({ - username_or_email, - password, - totp_2fa_token, - }); - switch (loginRes.state) { - case "failed": { - if (loginRes.msg === "missing_totp_token") { - i.setState({ showTotp: true }); - toast(i18n.t("enter_two_factor_code"), "info"); - } - - i.setState({ loginRes: { state: "empty" } }); - break; + const loginRes = await HttpService.client.login({ + username_or_email, + password, + totp_2fa_token, + }); + switch (loginRes.state) { + case "failed": { + if (loginRes.msg === "missing_totp_token") { + i.setState({ showTotp: true }); + toast(i18n.t("enter_two_factor_code"), "info"); } - case "success": { - UserService.Instance.login(loginRes.data); - const site = await HttpService.client.getSite({ - auth: myAuth(), - }); - - if (site.state === "success") { - UserService.Instance.myUserInfo = site.data.my_user; - } + i.setState({ loginRes: { state: "failed", msg: loginRes.msg } }); + break; + } - i.props.history.action === "PUSH" - ? i.props.history.back() - : i.props.history.replace("/"); + case "success": { + UserService.Instance.login(loginRes.data); + const site = await HttpService.client.getSite({ + auth: myAuth(), + }); - break; + if (site.state === "success") { + UserService.Instance.myUserInfo = site.data.my_user; } + + i.props.history.action === "PUSH" + ? i.props.history.back() + : i.props.history.replace("/"); + + break; } - } catch (error) { - i.setState({ loginRes: { state: "failed", msg: error.message } }); } } }