Skip to content

Commit

Permalink
impr(dev): add recaptcha site key to frontend env
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Feb 26, 2024
1 parent a6cc2b5 commit d23dad3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions frontend/src/ts/constants/env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type Config = {
backendUrl: string;
isDevelopment: boolean;
clientVersion: string;
recaptchaSiteKey: string;
};

//@ts-expect-error these get replaced by vite
Expand All @@ -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,
};
3 changes: 2 additions & 1 deletion frontend/src/ts/controllers/captcha-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const siteKey = "6Lc-V8McAAAAAJ7s6LGNe7MBZnRiwbsbiWts87aj";
import { envConfig } from "../constants/env-config";
const siteKey = envConfig.recaptchaSiteKey;

const captchas: Record<string, number> = {};

Expand Down
7 changes: 7 additions & 0 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d23dad3

Please sign in to comment.