Skip to content

Commit 2305176

Browse files
committed
impr(dev): add quick login button to frontend dev modal
!nuf
1 parent c6d1ea0 commit 2305176

5 files changed

Lines changed: 32 additions & 4 deletions

File tree

frontend/src/html/popups.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<div class="modal">
99
<div class="title">Dev options</div>
1010
<button class="generateData">generate data</button>
11+
<button class="quickLogin">quick login</button>
1112
<button class="toggleMediaQueryDebug">toggle media query debug</button>
1213
<button class="showTestNotifications">show test notifications</button>
1314
<button class="showRealWordsInput">show real words input</button>

frontend/src/ts/constants/env-config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ type Config = {
33
isDevelopment: boolean;
44
clientVersion: string;
55
recaptchaSiteKey: string;
6+
quickLoginEmail: string | undefined;
7+
quickLoginPassword: string | undefined;
68
};
79

810
//@ts-expect-error these get replaced by vite
@@ -13,10 +15,16 @@ const isDevelopment = IS_DEVELOPMENT;
1315
const clientVersion = CLIENT_VERSION;
1416
// @ts-expect-error
1517
const recaptchaSiteKey = RECAPTCHA_SITE_KEY;
18+
// @ts-expect-error
19+
const quickLoginEmail = QUICK_LOGIN_EMAIL;
20+
// @ts-expect-error
21+
const quickLoginPassword = QUICK_LOGIN_PASSWORD;
1622

1723
export const envConfig: Config = {
1824
backendUrl,
1925
isDevelopment,
2026
clientVersion,
2127
recaptchaSiteKey,
28+
quickLoginEmail,
29+
quickLoginPassword,
2230
};

frontend/src/ts/controllers/account-controller.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ if (Auth && ConnectionState.get()) {
276276
});
277277
}
278278

279-
async function signIn(): Promise<void> {
279+
export async function signIn(email: string, password: string): Promise<void> {
280280
if (Auth === undefined) {
281281
Notifications.add("Authentication uninitialized", -1);
282282
return;
@@ -292,8 +292,6 @@ async function signIn(): Promise<void> {
292292
LoginPage.showPreloader();
293293
LoginPage.disableInputs();
294294
LoginPage.disableSignUpButton();
295-
const email = ($(".pageLogin .login input")[0] as HTMLInputElement).value;
296-
const password = ($(".pageLogin .login input")[1] as HTMLInputElement).value;
297295

298296
if (email === "" || password === "") {
299297
Notifications.add("Please fill in all fields", 0);
@@ -627,7 +625,11 @@ async function signUp(): Promise<void> {
627625

628626
$(".pageLogin .login form").on("submit", (e) => {
629627
e.preventDefault();
630-
void signIn();
628+
const email =
629+
($(".pageLogin .login input")[0] as HTMLInputElement).value ?? "";
630+
const password =
631+
($(".pageLogin .login input")[1] as HTMLInputElement).value ?? "";
632+
void signIn(email, password);
631633
});
632634

633635
$(".pageLogin .login button.signInWithGoogle").on("click", () => {

frontend/src/ts/modals/dev-options.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AnimatedModal from "../utils/animated-modal";
33
import { showPopup } from "./simple-modals";
44
import * as Notifications from "../elements/notifications";
55
import { setMediaQueryDebugLevel } from "../ui";
6+
import { signIn } from "../controllers/account-controller";
67

78
let mediaQueryDebugLevel = 0;
89

@@ -47,6 +48,20 @@ async function setup(modalEl: HTMLElement): Promise<void> {
4748
$("#wordsInput").css("opacity", "1");
4849
void modal.hide();
4950
});
51+
modalEl.querySelector(".quickLogin")?.addEventListener("click", () => {
52+
if (
53+
envConfig.quickLoginEmail === undefined ||
54+
envConfig.quickLoginPassword === undefined
55+
) {
56+
Notifications.add(
57+
"Quick login credentials not set. Add QUICK_LOGIN_EMAIL and QUICK_LOGIN_PASSWORD to your frontend .env file.",
58+
-1
59+
);
60+
return;
61+
}
62+
void signIn(envConfig.quickLoginEmail, envConfig.quickLoginPassword);
63+
void modal.hide();
64+
});
5065
}
5166

5267
const modal = new AnimatedModal({

frontend/vite.config.dev.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default {
3737
RECAPTCHA_SITE_KEY: JSON.stringify(
3838
"6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
3939
),
40+
QUICK_LOGIN_EMAIL: JSON.stringify(process.env.QUICK_LOGIN_EMAIL),
41+
QUICK_LOGIN_PASSWORD: JSON.stringify(process.env.QUICK_LOGIN_PASSWORD),
4042
},
4143
build: {
4244
outDir: "../dist",

0 commit comments

Comments
 (0)