Selaa lähdekoodia

fix(login): illogical conditional

ayn2op 4 kuukautta sitten
vanhempi
sitoutus
9c9815544f
1 muutettua tiedostoa jossa 16 lisäystä ja 13 poistoa
  1. 16 13
      internal/login/form.go

+ 16 - 13
internal/login/form.go

@@ -70,22 +70,25 @@ func (f *Form) login() {
 		return
 	}
 
-	if resp.MFA && resp.TOTP {
-		code := f.form.GetFormItem(2).(*tview.InputField).GetText()
-		if code == "" {
-			f.onError(errors.New("code required"))
-			return
-		}
+	if resp.MFA {
+		switch {
+		case resp.TOTP:
+			code := f.form.GetFormItem(2).(*tview.InputField).GetText()
+			if code == "" {
+				f.onError(errors.New("code required"))
+				return
+			}
 
-		// Attempt to login using the code.
-		resp, err = client.TOTP(code, resp.Ticket)
-		if err != nil {
-			f.onError(err)
+			// Attempt to login using the code.
+			resp, err = client.TOTP(code, resp.Ticket)
+			if err != nil {
+				f.onError(err)
+				return
+			}
+		default:
+			f.onError(errors.New("unsupported mfa type"))
 			return
 		}
-	} else {
-		f.onError(errors.New("unsupported mfa type"))
-		return
 	}
 
 	if resp.Token == "" {