add api key

This commit is contained in:
2024-05-10 12:57:38 +02:00
parent ec166b8b5b
commit e063020ed1
2 changed files with 5 additions and 5 deletions

6
src/env/client.mjs vendored
View File

@@ -5,7 +5,7 @@ const _clientEnv = clientSchema.safeParse(clientEnv);
export const formatErrors = ( export const formatErrors = (
/** @type {import('zod').ZodFormattedError<Map<string,string>,string>} */ /** @type {import('zod').ZodFormattedError<Map<string,string>,string>} */
errors, errors
) => ) =>
Object.entries(errors) Object.entries(errors)
.map(([name, value]) => { .map(([name, value]) => {
@@ -17,7 +17,7 @@ export const formatErrors = (
if (!_clientEnv.success) { if (!_clientEnv.success) {
console.error( console.error(
"❌ Invalid environment variables:\n", "❌ Invalid environment variables:\n",
...formatErrors(_clientEnv.error.format()), ...formatErrors(_clientEnv.error.format())
); );
throw new Error("Invalid environment variables"); throw new Error("Invalid environment variables");
} }
@@ -25,7 +25,7 @@ if (!_clientEnv.success) {
for (let key of Object.keys(_clientEnv.data)) { for (let key of Object.keys(_clientEnv.data)) {
if (!key.startsWith("NEXT_PUBLIC_")) { if (!key.startsWith("NEXT_PUBLIC_")) {
console.warn( console.warn(
`❌ Invalid public environment variable name: ${key}. It must begin with 'NEXT_PUBLIC_'`, `❌ Invalid public environment variable name: ${key}. It must begin with 'NEXT_PUBLIC_'`
); );
throw new Error("Invalid public environment variable name"); throw new Error("Invalid public environment variable name");

4
src/env/server.mjs vendored
View File

@@ -3,15 +3,15 @@
* This file is included in `/next.config.mjs` which ensures the app isn't built with invalid env vars. * This file is included in `/next.config.mjs` which ensures the app isn't built with invalid env vars.
* It has to be a `.mjs`-file to be imported there. * It has to be a `.mjs`-file to be imported there.
*/ */
import { serverSchema } from "./schema.mjs";
import { env as clientEnv, formatErrors } from "./client.mjs"; import { env as clientEnv, formatErrors } from "./client.mjs";
import { serverSchema } from "./schema.mjs";
const _serverEnv = serverSchema.safeParse(process.env); const _serverEnv = serverSchema.safeParse(process.env);
if (!_serverEnv.success) { if (!_serverEnv.success) {
console.error( console.error(
"❌ Invalid environment variables:\n", "❌ Invalid environment variables:\n",
...formatErrors(_serverEnv.error.format()), ...formatErrors(_serverEnv.error.format())
); );
throw new Error("Invalid environment variables"); throw new Error("Invalid environment variables");
} }