feat: implement turnstile on signup (#13913)
* wip * feat: turnstile + removal of trpcState * fix: use react-turnstile * fix: i18n hydration errors * wip: server side validation for cf token * fix: hide in e2e tests * feat:throw on error of token * fix: set correct form values onVerify * fix: use getIp for remoteIp and use correct header for token input * chore: update .env.example * fix: Update .env.example * Update apps/web/pages/signup.tsx * chore: fix typo * fix: typo * feat: hide until error * feat: appearance interaction only * remove cloudflare from e2e * fix: legacyBehavior * fix links + wait for load * fix: signup tests * test: wait for load state --------- Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
11 files changed
+243
-102
No files matched your search
@@ -146,5 +146,6 @@ export const BOOKER_NUMBER_OF_DAYS_TO_LOAD = parseInt(
|
||||
0
|
||||
);
|
||||
|
||||
export const CLOUDFLARE_SITE_ID = process.env.NEXT_PUBLIC_CLOUDFLARE_SITEKEY;
|
||||
export const MINIMUM_NUMBER_OF_ORG_SEATS = 30;
|
||||
export const ORG_SELF_SERVE_ENABLED = process.env.NEXT_PUBLIC_ORG_SELF_SERVE_ENABLED === "1";
|
||||
@@ -0,0 +1,35 @@
|
||||
import { HttpError } from "../http-error";
|
||||
|
||||
const TURNSTILE_SECRET_ID = process.env.CLOUDFLARE_TURNSTILE_SECRET;
|
||||
|
||||
export async function checkCfTurnstileToken({ token, remoteIp }: { token?: string; remoteIp: string }) {
|
||||
// This means the instant doesnt have turnstile enabled - we skip the check and just return success.
|
||||
// OR the instance is running in CI so we skip these checks also
|
||||
if (!TURNSTILE_SECRET_ID || !!process.env.NEXT_PUBLIC_IS_E2E) {
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
throw new HttpError({ statusCode: 401, message: "Invalid cloudflare token" });
|
||||
}
|
||||
|
||||
const form = new URLSearchParams();
|
||||
form.append("secret", TURNSTILE_SECRET_ID);
|
||||
form.append("response", token);
|
||||
form.append("remoteip", remoteIp);
|
||||
|
||||
const result = await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
||||
method: "POST",
|
||||
body: form,
|
||||
});
|
||||
|
||||
const data = await result.json();
|
||||
|
||||
if (!data["success"]) {
|
||||
throw new HttpError({ statusCode: 401, message: "Invalid cloudflare token" });
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in new issue
Block a user