Skip to content

Commit 53c74cd

Browse files
authored
sync login ui with backend (#815)
2 parents 2b07354 + d599429 commit 53c74cd

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

resources/scripts/download.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import fs from 'fs'
1010
*/
1111
export async function downloadWithRedirects(url, destinationPath) {
1212
return new Promise((resolve, reject) => {
13-
const timeoutMs = 3 * 60 * 1000; // 3 minutes
13+
const timeoutMs = 5 * 60 * 1000; // 10 minutes
1414
const timeout = setTimeout(() => {
1515
reject(new Error(`timeout(${timeoutMs / 1000} seconds)`));
1616
}, timeoutMs);
@@ -113,4 +113,3 @@ export async function downloadWithRedirects(url, destinationPath) {
113113
request(url)
114114
})
115115
}
116-

src/pages/Login.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ export default function Login() {
6565
return !newErrors.email && !newErrors.password;
6666
};
6767

68+
const getLoginErrorMessage = (data: any) => {
69+
if (!data || typeof data !== "object" || typeof data.code !== "number") {
70+
return "";
71+
}
72+
73+
if (data.code === 0) {
74+
return "";
75+
}
76+
77+
if (data.code === 10) {
78+
return data.text || t("layout.login-failed-please-check-your-email-and-password");
79+
}
80+
81+
if (data.code === 1 && Array.isArray(data.error) && data.error.length > 0) {
82+
const firstError = data.error[0];
83+
if (typeof firstError === "string") {
84+
return firstError;
85+
}
86+
if (typeof firstError?.msg === "string") {
87+
return firstError.msg;
88+
}
89+
if (typeof firstError?.message === "string") {
90+
return firstError.message;
91+
}
92+
}
93+
94+
return data.text || t("layout.login-failed-please-try-again");
95+
};
96+
6897
const handleInputChange = (field: string, value: string) => {
6998
setFormData((prev) => ({
7099
...prev,
@@ -97,8 +126,9 @@ export default function Login() {
97126
password: formData.password,
98127
});
99128

100-
if (data.code === 10) {
101-
setGeneralError(data.text || t("layout.login-failed-please-try-again"));
129+
const errorMessage = getLoginErrorMessage(data);
130+
if (errorMessage) {
131+
setGeneralError(errorMessage);
102132
return;
103133
}
104134

@@ -122,8 +152,9 @@ export default function Login() {
122152
token: token,
123153
});
124154

125-
if (data.code === 10) {
126-
setGeneralError(data.text || t("layout.login-failed-please-try-again"));
155+
const errorMessage = getLoginErrorMessage(data);
156+
if (errorMessage) {
157+
setGeneralError(errorMessage);
127158
return;
128159
}
129160
console.log("data", data);
@@ -294,7 +325,13 @@ export default function Login() {
294325
<Button
295326
variant="ghost"
296327
size="sm"
297-
onClick={() => navigate("/signup")}
328+
onClick={() =>
329+
window.open(
330+
"https://www.eigent.ai/signup",
331+
"_blank",
332+
"noopener,noreferrer"
333+
)
334+
}
298335
>
299336
{t("layout.sign-up")}
300337
</Button>

0 commit comments

Comments
 (0)