Skip to content

Commit 6a0b343

Browse files
committed
fixes
1 parent 2e80466 commit 6a0b343

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

resources/lang/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
"account_modal": {
143143
"title": "Account",
144144
"logged_in_as": "Logged in as {email}",
145-
"logged_in_with_discord": "Logged in with Discord"
145+
"logged_in_with_discord": "Logged in with Discord",
146+
"recovery_email_sent": "Recovery email sent to {email}"
146147
},
147148
"map": {
148149
"map": "Map",

src/client/AccountModal.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ export class AccountModal extends LitElement {
184184
});
185185

186186
if (response.ok) {
187-
alert(`Recovery email sent to: ${this.email}`);
187+
alert(
188+
translateText("account_modal.recovery_email_sent", {
189+
email: this.email,
190+
}),
191+
);
188192
this.close();
189193
} else {
190194
console.error(
@@ -219,15 +223,10 @@ export class AccountModal extends LitElement {
219223
}
220224

221225
private async handleLogout() {
222-
try {
223-
await logOut();
224-
this.close();
225-
// Refresh the page after logout to update the UI state
226-
window.location.reload();
227-
} catch (error) {
228-
console.error("Error during logout:", error);
229-
alert("Error during logout. Please try again.");
230-
}
226+
await logOut();
227+
this.close();
228+
// Refresh the page after logout to update the UI state
229+
window.location.reload();
231230
}
232231
}
233232

src/client/Main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ class Client {
449449
if (token) {
450450
strip();
451451
window.addEventListener("beforeunload", () => {
452-
// The page refreshes after token login, so we need to save the pattern name
453-
// in case it is unset during login.
452+
// The page reloads after token login, so we need to save the pattern name
453+
// in case it is unset during reload.
454454
this.userSettings.setSelectedPatternName(patternName);
455455
});
456456
this.tokenLoginModal.open(token);
@@ -466,7 +466,7 @@ class Client {
466466

467467
if (!token) {
468468
alertAndStrip(
469-
`login failed! got url ${window.location.href} Please try again.`,
469+
`login failed! Please try again later or contact support.`,
470470
);
471471
return;
472472
}

src/client/jwt.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,21 @@ export async function tokenLogin(token: string): Promise<string | null> {
7575
const response = await fetch(
7676
`${getApiBase()}/login/token?login-token=${token}`,
7777
);
78-
if (response.status === 200) {
79-
const json = await response.json();
80-
const { jwt, email } = json;
81-
const payload = decodeJwt(jwt);
82-
const result = TokenPayloadSchema.safeParse(payload);
83-
if (!result.success) {
84-
console.error("Invalid token", result.error, result.error.message);
85-
return null;
86-
}
87-
clearToken();
88-
localStorage.setItem("token", jwt);
89-
return email;
90-
} else {
78+
if (response.status !== 200) {
9179
console.error("Token login failed", response);
9280
return null;
9381
}
82+
const json = await response.json();
83+
const { jwt, email } = json;
84+
const payload = decodeJwt(jwt);
85+
const result = TokenPayloadSchema.safeParse(payload);
86+
if (!result.success) {
87+
console.error("Invalid token", result.error, result.error.message);
88+
return null;
89+
}
90+
clearToken();
91+
localStorage.setItem("token", jwt);
92+
return email;
9493
}
9594

9695
export function getAuthHeader(): string {

0 commit comments

Comments
 (0)