Skip to content

Commit 69e96f2

Browse files
committed
refactor: move captcha modal call from auth to Register component
1 parent 962ebc9 commit 69e96f2

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

frontend/src/ts/auth.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from "firebase/auth";
1010

1111
import Ape from "./ape";
12-
import { showRegisterCaptchaModal } from "./components/modals/RegisterCaptchaModal";
1312
import { updateFromServer as updateConfigFromServer } from "./config/remote";
1413
import * as DB from "./db";
1514
import { authEvent } from "./events/auth";
@@ -229,14 +228,11 @@ export async function signUp(
229228
name: string,
230229
email: string,
231230
password: string,
231+
captchaToken: string,
232232
): Promise<AuthResult> {
233233
if (!isAuthAvailable()) {
234234
return { success: false, message: "Authentication uninitialized" };
235235
}
236-
const captchaToken = await showRegisterCaptchaModal();
237-
if (captchaToken === undefined || captchaToken === "") {
238-
return { success: false, message: "Please complete the captcha" };
239-
}
240236

241237
try {
242238
const createdAuthUser = await createUserWithEmailAndPassword(

frontend/src/ts/components/pages/login/Register.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { isDevEnvironment } from "../../../utils/env";
2323
import { remoteValidationForm } from "../../../utils/remote-validation";
2424
import { H3 } from "../../common/Headers";
25+
import { showRegisterCaptchaModal } from "../../modals/RegisterCaptchaModal";
2526
import { InputField } from "../../ui/form/InputField";
2627
import { SubmitButton } from "../../ui/form/SubmitButton";
2728
import {
@@ -88,8 +89,19 @@ export function Register(): JSXElement {
8889
},
8990
onSubmit: async ({ value }) => {
9091
disableLoginPageInputs();
92+
const captchaToken = await showRegisterCaptchaModal();
93+
if (captchaToken === undefined || captchaToken === "") {
94+
showErrorNotification("Please complete the captcha");
95+
enableLoginPageInputs();
96+
return;
97+
}
9198
try {
92-
const data = await signUp(value.username, value.email, value.password);
99+
const data = await signUp(
100+
value.username,
101+
value.email,
102+
value.password,
103+
captchaToken,
104+
);
93105
if (!data.success) {
94106
showErrorNotification(data.message);
95107
}

0 commit comments

Comments
 (0)