diff --git a/frontend/src/ts/constants/env-config.ts b/frontend/src/ts/constants/env-config.ts index 9bf3a8da086e..98a192a12427 100644 --- a/frontend/src/ts/constants/env-config.ts +++ b/frontend/src/ts/constants/env-config.ts @@ -2,6 +2,7 @@ type Config = { backendUrl: string; isDevelopment: boolean; clientVersion: string; + recaptchaSiteKey: string; }; //@ts-expect-error these get replaced by vite @@ -10,9 +11,12 @@ const backendUrl = BACKEND_URL; const isDevelopment = IS_DEVELOPMENT; // @ts-expect-error const clientVersion = CLIENT_VERSION; +// @ts-expect-error +const recaptchaSiteKey = RECAPTCHA_SITE_KEY; export const envConfig: Config = { backendUrl, isDevelopment, clientVersion, + recaptchaSiteKey, }; diff --git a/frontend/src/ts/controllers/captcha-controller.ts b/frontend/src/ts/controllers/captcha-controller.ts index 497d92f831a6..09ed2b68a5db 100644 --- a/frontend/src/ts/controllers/captcha-controller.ts +++ b/frontend/src/ts/controllers/captcha-controller.ts @@ -1,4 +1,5 @@ -const siteKey = "6Lc-V8McAAAAAJ7s6LGNe7MBZnRiwbsbiWts87aj"; +import { envConfig } from "../constants/env-config"; +const siteKey = envConfig.recaptchaSiteKey; const captchas: Record = {}; diff --git a/frontend/vite.config.js b/frontend/vite.config.js index aa2dcd0d5a29..4106d33316c8 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -121,6 +121,9 @@ const BASE_CONFIG = { ), IS_DEVELOPMENT: JSON.stringify(true), CLIENT_VERSION: JSON.stringify("DEVELOPMENT_CLIENT"), + RECAPTCHA_SITE_KEY: JSON.stringify( + "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI" + ), }, optimizeDeps: { include: ["jquery"], @@ -190,11 +193,15 @@ const BUILD_CONFIG = { BACKEND_URL: JSON.stringify("https://api.monkeytype.com"), IS_DEVELOPMENT: JSON.stringify(false), CLIENT_VERSION: JSON.stringify(buildClientVersion()), + RECAPTCHA_SITE_KEY: JSON.stringify(process.env.RECAPTCHA_SITE_KEY), }, }; export default defineConfig(({ command }) => { if (command === "build") { + if (process.env.RECAPTCHA_SITE_KEY === undefined) { + throw new Error(".env: RECAPTCHA_SITE_KEY is not defined"); + } return mergeConfig(BASE_CONFIG, BUILD_CONFIG); } else { return BASE_CONFIG;