mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-29 12:04:04 +00:00
handle login failures correctly
This commit is contained in:
parent
55512a2eae
commit
93e3598328
|
@ -160,42 +160,38 @@ export class Login extends Component<any, State> {
|
||||||
if (username_or_email && password) {
|
if (username_or_email && password) {
|
||||||
i.setState({ loginRes: { state: "loading" } });
|
i.setState({ loginRes: { state: "loading" } });
|
||||||
|
|
||||||
try {
|
const loginRes = await HttpService.client.login({
|
||||||
const loginRes = await HttpService.client.login({
|
username_or_email,
|
||||||
username_or_email,
|
password,
|
||||||
password,
|
totp_2fa_token,
|
||||||
totp_2fa_token,
|
});
|
||||||
});
|
switch (loginRes.state) {
|
||||||
switch (loginRes.state) {
|
case "failed": {
|
||||||
case "failed": {
|
if (loginRes.msg === "missing_totp_token") {
|
||||||
if (loginRes.msg === "missing_totp_token") {
|
i.setState({ showTotp: true });
|
||||||
i.setState({ showTotp: true });
|
toast(i18n.t("enter_two_factor_code"), "info");
|
||||||
toast(i18n.t("enter_two_factor_code"), "info");
|
|
||||||
}
|
|
||||||
|
|
||||||
i.setState({ loginRes: { state: "empty" } });
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "success": {
|
i.setState({ loginRes: { state: "failed", msg: loginRes.msg } });
|
||||||
UserService.Instance.login(loginRes.data);
|
break;
|
||||||
const site = await HttpService.client.getSite({
|
}
|
||||||
auth: myAuth(),
|
|
||||||
});
|
case "success": {
|
||||||
|
UserService.Instance.login(loginRes.data);
|
||||||
if (site.state === "success") {
|
const site = await HttpService.client.getSite({
|
||||||
UserService.Instance.myUserInfo = site.data.my_user;
|
auth: myAuth(),
|
||||||
}
|
});
|
||||||
|
|
||||||
i.props.history.action === "PUSH"
|
if (site.state === "success") {
|
||||||
? i.props.history.back()
|
UserService.Instance.myUserInfo = site.data.my_user;
|
||||||
: i.props.history.replace("/");
|
}
|
||||||
|
|
||||||
break;
|
i.props.history.action === "PUSH"
|
||||||
}
|
? i.props.history.back()
|
||||||
|
: i.props.history.replace("/");
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
i.setState({ loginRes: { state: "failed", msg: error.message } });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue