Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
π§βπ» Improve support for type-safe env vars (#1195)
Luke Vella526122b19ea5
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 444154272..17392d97c 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -31,15 +31,15 @@"@rallly/tailwind-config": "*","@rallly/ui": "*","@svgr/webpack": "^6.5.1",+ "@t3-oss/env-nextjs": "^0.10.1","@tanstack/react-query": "^4.0.0","@tanstack/react-table": "^8.9.1","@trpc/client": "^10.13.0","@trpc/next": "^10.13.0","@trpc/react-query": "^10.13.0","@upstash/ratelimit": "^1.2.1",- "@vercel/kv": "^2.0.0",- "request-ip": "^3.3.0","@vercel/functions": "^1.0.2",+ "@vercel/kv": "^2.0.0","accept-language-parser": "^1.5.0","autoprefixer": "^10.4.13","class-variance-authority": "^0.7.0",@@ -54,6 +54,8 @@"intl-messageformat": "^10.3.4","iron-session": "^6.3.1","js-cookie": "^3.0.1",+ "linkify-react": "^4.1.3",+ "linkifyjs": "^4.1.3","lodash": "^4.17.21","lucide-react": "^0.367.0","micro": "^10.0.1",@@ -68,10 +70,9 @@"react-hook-form": "^7.42.1","react-hook-form-persist": "^3.0.0","react-i18next": "^12.1.4",- "linkifyjs": "^4.1.3",- "linkify-react": "^4.1.3","react-remove-scroll": "^2.5.6","react-use": "^17.4.0",+ "request-ip": "^3.3.0","smoothscroll-polyfill": "^0.4.4","spacetime": "^7.4.7","superjson": "^2.0.0",@@ -79,20 +80,20 @@},"devDependencies": {"@playwright/test": "^1.39.0",- "@rallly/tsconfig": "*","@rallly/eslint-config": "*",+ "@rallly/tsconfig": "*","@types/accept-language-parser": "^1.5.3","@types/color-hash": "^1.0.2",- "@types/request-ip": "^0.0.41","@types/lodash": "^4.14.178","@types/react-big-calendar": "^1.8.8",+ "@types/request-ip": "^0.0.41","@types/smoothscroll-polyfill": "^0.3.1","cheerio": "^1.0.0-rc.12","cross-env": "^7.0.3",- "vitest": "^1.3.1","i18next-scanner": "^4.2.0","i18next-scanner-typescript": "^1.1.1","smtp-tester": "^2.1.0",+ "vitest": "^1.3.1","wait-on": "^6.0.1"}}diff --git a/apps/web/src/app/posthog.ts b/apps/web/src/app/posthog.tsindex bc1ec7271..8e14ae2eb 100644--- a/apps/web/src/app/posthog.ts+++ b/apps/web/src/app/posthog.ts@@ -1,11 +1,13 @@import { waitUntil } from "@vercel/functions";import { PostHog } from "posthog-node";+import { env } from "@/env";+function PostHogClient() {- if (!process.env.NEXT_PUBLIC_POSTHOG_API_KEY) return null;+ if (!env.NEXT_PUBLIC_POSTHOG_API_KEY) return null;- const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_API_KEY, {- host: process.env.NEXT_PUBLIC_POSTHOG_API_HOST,+ const posthogClient = new PostHog(env.NEXT_PUBLIC_POSTHOG_API_KEY, {+ host: env.NEXT_PUBLIC_POSTHOG_API_HOST,flushAt: 1,flushInterval: 0,});diff --git a/apps/web/src/env.ts b/apps/web/src/env.tsnew file mode 100644index 000000000..d86588272--- /dev/null+++ b/apps/web/src/env.ts@@ -0,0 +1,86 @@+import { createEnv } from "@t3-oss/env-nextjs";+import { z } from "zod";++export const env = createEnv({+ /*+ * Serverside Environment variables, not available on the client.+ * Will throw if you access these variables on the client.+ */+ server: {+ DATABASE_URL: z.string().url(),+ NODE_ENV: z+ .enum(["development", "production", "test"])+ .default("development"),+ SECRET_PASSWORD: z.string().min(32),+ /**+ * OIDC Configuration+ */+ OIDC_NAME: z.string().default("OpenID Connect"),+ OIDC_DISCOVERY_URL: z.string().optional(),+ OIDC_CLIENT_ID: z.string().optional(),+ OIDC_CLIENT_SECRET: z.string().optional(),+ /**+ * Email Provider+ * Choose which service provider to use for sending emails.+ * Make sure to configure the corresponding environment variables.+ */+ EMAIL_PROVIDER: z.enum(["smtp", "ses"]).default("smtp"),+ /**+ * SMTP Configuration+ */+ SMTP_HOST: z.string().optional(),+ SMTP_USER: z.string().optional(),+ SMTP_PWD: z.string().optional(),+ SMTP_SECURE: z.string().optional(),+ SMTP_PORT: z.string().optional(),+ /**+ * AWS SES Configuration+ */+ AWS_ACCESS_KEY_ID: z.string().optional(),+ AWS_SECRET_ACCESS_KEY: z.string().optional(),+ AWS_REGION: z.string().optional(),+ /**+ * Comma separated list of email addresses that are allowed to register and login.+ * If not set, all emails are allowed. Wildcard characters are supported.+ *+ * Example: "[email protected], *@example.com, *@*.example.com"+ */+ ALLOWED_EMAILS: z.string().optional(),+ },+ /*+ * Environment variables available on the client (and server).+ *+ * π‘ You'll get type errors if these are not prefixed with NEXT_PUBLIC_.+ */+ client: {+ NEXT_PUBLIC_POSTHOG_API_KEY: z.string().optional(),+ NEXT_PUBLIC_POSTHOG_API_HOST: z.string().url().optional(),+ },+ /*+ * Due to how Next.js bundles environment variables on Edge and Client,+ * we need to manually destructure them to make sure all are included in bundle.+ *+ * π‘ You'll get type errors if not all variables from `server` & `client` are included here.+ */+ runtimeEnv: {+ DATABASE_URL: process.env.DATABASE_URL,+ NODE_ENV: process.env.NODE_ENV,+ SECRET_PASSWORD: process.env.SECRET_PASSWORD,+ OIDC_NAME: process.env.OIDC_NAME,+ OIDC_DISCOVERY_URL: process.env.OIDC_DISCOVERY_URL,+ OIDC_CLIENT_ID: process.env.OIDC_CLIENT_ID,+ OIDC_CLIENT_SECRET: process.env.OIDC_CLIENT_SECRET,+ EMAIL_PROVIDER: process.env.EMAIL_PROVIDER,+ SMTP_HOST: process.env.SMTP_HOST,+ SMTP_USER: process.env.SMTP_USER,+ SMTP_PWD: process.env.SMTP_PWD,+ SMTP_SECURE: process.env.SMTP_SECURE,+ SMTP_PORT: process.env.SMTP_PORT,+ AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,+ AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,+ AWS_REGION: process.env.AWS_REGION,+ ALLOWED_EMAILS: process.env.ALLOWED_EMAILS,+ NEXT_PUBLIC_POSTHOG_API_KEY: process.env.NEXT_PUBLIC_POSTHOG_API_KEY,+ NEXT_PUBLIC_POSTHOG_API_HOST: process.env.NEXT_PUBLIC_POSTHOG_API_HOST,+ },+});diff --git a/yarn.lock b/yarn.lockindex bc8fab197..fa6709d31 100644--- a/yarn.lock+++ b/yarn.lock@@ -4750,6 +4750,18 @@resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.5.tgz#043b731d4f56a79b4897a3de1af35e75d56bc63a"integrity sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==+"@t3-oss/[email protected]":+ version "0.10.1"+ resolved "https://registry.yarnpkg.com/@t3-oss/env-core/-/env-core-0.10.1.tgz#388da647053063f7d9a7b6830537939daf697fa2"+ integrity sha512-GcKZiCfWks5CTxhezn9k5zWX3sMDIYf6Kaxy2Gx9YEQftFcz8hDRN56hcbylyAO3t4jQnQ5ifLawINsNgCDpOg==++"@t3-oss/env-nextjs@^0.10.1":+ version "0.10.1"+ resolved "https://registry.yarnpkg.com/@t3-oss/env-nextjs/-/env-nextjs-0.10.1.tgz#abe50e7063fcfdecb7da4371172480c99e9c6dc0"+ integrity sha512-iy2qqJLnFh1RjEWno2ZeyTu0ufomkXruUsOZludzDIroUabVvHsrSjtkHqwHp1/pgPUzN3yBRHMILW162X7x2Q==+ dependencies:+ "@t3-oss/env-core" "0.10.1"+"@tailwindcss/typography@^0.5.13":version "0.5.13"resolved "https://registry.yarnpkg.com/@tailwindcss/typography/-/typography-0.5.13.tgz#cd788a4fa4d0ca2506e242d512f377b22c1f7932"