]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/home/login.tsx
handle login failures correctly
[lemmy-ui.git] / src / shared / components / home / login.tsx
index 3ddb4bc1d2c126126f142818757d0368c9379c5f..841a3d2b2c59f32bc134183f0860eaaa576305f2 100644 (file)
@@ -160,42 +160,38 @@ export class Login extends Component<any, State> {
     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 } });
       }
     }
   }