mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-28 11:40:25 +00:00
sync login ui with backend
This commit is contained in:
parent
8955dbb725
commit
3bfdcdb646
2 changed files with 43 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ import fs from 'fs'
|
|||
*/
|
||||
export async function downloadWithRedirects(url, destinationPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutMs = 3 * 60 * 1000; // 3 minutes
|
||||
const timeoutMs = 5 * 60 * 1000; // 10 minutes
|
||||
const timeout = setTimeout(() => {
|
||||
reject(new Error(`timeout(${timeoutMs / 1000} seconds)`));
|
||||
}, timeoutMs);
|
||||
|
|
@ -113,4 +113,3 @@ export async function downloadWithRedirects(url, destinationPath) {
|
|||
request(url)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,35 @@ export default function Login() {
|
|||
return !newErrors.email && !newErrors.password;
|
||||
};
|
||||
|
||||
const getLoginErrorMessage = (data: any) => {
|
||||
if (!data || typeof data !== "object" || typeof data.code !== "number") {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (data.code === 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (data.code === 10) {
|
||||
return data.text || t("layout.login-failed-please-check-your-email-and-password");
|
||||
}
|
||||
|
||||
if (data.code === 1 && Array.isArray(data.error) && data.error.length > 0) {
|
||||
const firstError = data.error[0];
|
||||
if (typeof firstError === "string") {
|
||||
return firstError;
|
||||
}
|
||||
if (typeof firstError?.msg === "string") {
|
||||
return firstError.msg;
|
||||
}
|
||||
if (typeof firstError?.message === "string") {
|
||||
return firstError.message;
|
||||
}
|
||||
}
|
||||
|
||||
return data.text || t("layout.login-failed-please-try-again");
|
||||
};
|
||||
|
||||
const handleInputChange = (field: string, value: string) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
|
|
@ -97,8 +126,9 @@ export default function Login() {
|
|||
password: formData.password,
|
||||
});
|
||||
|
||||
if (data.code === 10) {
|
||||
setGeneralError(data.text || t("layout.login-failed-please-try-again"));
|
||||
const errorMessage = getLoginErrorMessage(data);
|
||||
if (errorMessage) {
|
||||
setGeneralError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -122,8 +152,9 @@ export default function Login() {
|
|||
token: token,
|
||||
});
|
||||
|
||||
if (data.code === 10) {
|
||||
setGeneralError(data.text || t("layout.login-failed-please-try-again"));
|
||||
const errorMessage = getLoginErrorMessage(data);
|
||||
if (errorMessage) {
|
||||
setGeneralError(errorMessage);
|
||||
return;
|
||||
}
|
||||
console.log("data", data);
|
||||
|
|
@ -294,7 +325,13 @@ export default function Login() {
|
|||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate("/signup")}
|
||||
onClick={() =>
|
||||
window.open(
|
||||
"https://www.eigent.ai/signup",
|
||||
"_blank",
|
||||
"noopener,noreferrer"
|
||||
)
|
||||
}
|
||||
>
|
||||
{t("layout.sign-up")}
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue