diff --git a/resources/lang/en.json b/resources/lang/en.json
index ec27601e8..92fe6a940 100644
--- a/resources/lang/en.json
+++ b/resources/lang/en.json
@@ -157,10 +157,15 @@
},
"account_modal": {
"title": "Account",
- "logged_in_as": "Logged in as {email}",
+ "logged_in_as": "Logged in as {account_name}",
"fetching_account": "Fetching account information...",
"logged_in_with_discord": "Logged in with Discord",
- "recovery_email_sent": "Recovery email sent to {email}"
+ "recovery_email_sent": "Recovery email sent to {email}",
+ "player_id": "Player ID: {id}",
+ "not_found": "Not Found",
+ "clear_session": "Clear Session",
+ "failed_to_send_recovery_email": "Failed to send recovery email",
+ "enter_email_address": "Please enter an email address"
},
"stats_modal": {
"title": "Stats",
@@ -704,6 +709,7 @@
"colors": "Colors",
"purchase": "Purchase",
"show_only_owned": "My Skins",
+ "not_logged_in": "Not logged in",
"blocked": {
"login": "You must be logged in to access this skin.",
"purchase": "Purchase this skin to unlock it."
diff --git a/src/client/AccountModal.ts b/src/client/AccountModal.ts
index e20a9613e..6c9f6ba48 100644
--- a/src/client/AccountModal.ts
+++ b/src/client/AccountModal.ts
@@ -5,19 +5,14 @@ import {
PlayerStatsTree,
UserMeResponse,
} from "../core/ApiSchemas";
+import { fetchPlayerById, getUserMe } from "./Api";
+import { discordLogin, logOut, sendMagicLink } from "./Auth";
import "./components/baseComponents/stats/DiscordUserHeader";
import "./components/baseComponents/stats/GameList";
import "./components/baseComponents/stats/PlayerStatsTable";
import "./components/baseComponents/stats/PlayerStatsTree";
import "./components/Difficulties";
import "./components/PatternButton";
-import {
- discordLogin,
- fetchPlayerById,
- getApiBase,
- getUserMe,
- logOut,
-} from "./jwt";
import { isInIframe, translateText } from "./Utils";
@customElement("account-modal")
@@ -30,10 +25,7 @@ export class AccountModal extends LitElement {
@state() private email: string = "";
@state() private isLoadingUser: boolean = false;
- private loggedInEmail: string | null = null;
- private loggedInDiscord: string | null = null;
private userMeResponse: UserMeResponse | null = null;
- private playerId: string | null = null;
private statsTree: PlayerStatsTree | null = null;
private recentGames: PlayerGame[] = [];
@@ -44,8 +36,7 @@ export class AccountModal extends LitElement {
const customEvent = event as CustomEvent;
if (customEvent.detail) {
this.userMeResponse = customEvent.detail as UserMeResponse;
- this.playerId = this.userMeResponse?.player?.publicId;
- if (this.playerId === undefined) {
+ if (this.userMeResponse?.player?.publicId === undefined) {
this.statsTree = null;
this.recentGames = [];
}
@@ -67,31 +58,90 @@ export class AccountModal extends LitElement {
id="account-modal"
title="${translateText("account_modal.title") || "Account"}"
>
- ${this.renderInner()}
+ ${this.isLoadingUser
+ ? html`
+
+
+ ${translateText("account_modal.fetching_account")}
+
+
+
+ `
+ : this.renderInner()}
`;
}
private renderInner() {
- if (this.isLoadingUser) {
- return html`
-
-
${translateText("account_modal.fetching_account")}
-
-
- `;
- }
- if (this.loggedInDiscord) {
- return this.renderLoggedInDiscord();
- } else if (this.loggedInEmail) {
- return this.renderLoggedInEmail();
+ if (this.userMeResponse?.user) {
+ return this.renderAccountInfo();
} else {
return this.renderLoginOptions();
}
}
+ private renderAccountInfo() {
+ return html`
+
+
+
+ ${translateText("account_modal.player_id", {
+ id:
+ this.userMeResponse?.player?.publicId ??
+ translateText("account_modal.not_found"),
+ })}
+
+
+
+
${this.renderLoggedInAs()}
+
+
+
+
+ ${this.renderPlayerStats()}
+
+ `;
+ }
+
+ private renderLoggedInAs(): TemplateResult {
+ const me = this.userMeResponse?.user;
+ if (me?.discord) {
+ return html`
+ ${translateText("account_modal.logged_in_as", {
+ account_name: me.discord.global_name ?? "",
+ })}
+
+ ${this.renderLogoutButton()}`;
+ } else if (me?.email) {
+ return html`
+ ${translateText("account_modal.logged_in_as", {
+ account_name: me.email,
+ })}
+
+ ${this.renderLogoutButton()}`;
+ }
+ return this.renderLoginOptions();
+ }
+
+ private renderPlayerStats(): TemplateResult {
+ return html`
+
+
+ this.viewGame(id)}
+ >
+ `;
+ }
+
private viewGame(gameId: string): void {
this.close();
const path = location.pathname;
@@ -103,46 +153,7 @@ export class AccountModal extends LitElement {
window.dispatchEvent(new HashChangeEvent("hashchange"));
}
- private renderLoggedInDiscord() {
- return html`
-
-
-
- Logged in with Discord as ${this.loggedInDiscord}
-
- ${this.logoutButton()}
-
-
-
-
-
-
this.viewGame(id)}
- >
-
-
- `;
- }
-
- private renderLoggedInEmail(): TemplateResult {
- return html`
-
-
-
- Logged in as ${this.loggedInEmail}
-
-
- ${this.logoutButton()}
-
- `;
- }
-
- private logoutButton(): TemplateResult {
+ private renderLogoutButton(): TemplateResult {
return html`