From b43ecd267565e31b902b344f215d8f60e66abb03 Mon Sep 17 00:00:00 2001
From: nolostra <saiesh1400@gmail.com>
Date: Fri, 20 Sep 2024 14:06:13 +0530
Subject: [PATCH] fix: comment fixes

---
 src/app/api/upload-to-cdn/route.ts   |  7 ++---
 src/components/gmaps-autosuggest.tsx |  3 ++-
 src/env.ts                           | 25 ------------------
 src/env/client.ts                    | 13 ++++++++++
 src/env/server.ts                    | 38 ++++++++++++++++++++++++++++
 5 files changed, 57 insertions(+), 29 deletions(-)
 delete mode 100644 src/env.ts
 create mode 100644 src/env/client.ts
 create mode 100644 src/env/server.ts

diff --git a/src/app/api/upload-to-cdn/route.ts b/src/app/api/upload-to-cdn/route.ts
index 35167c03..9f34d64a 100644
--- a/src/app/api/upload-to-cdn/route.ts
+++ b/src/app/api/upload-to-cdn/route.ts
@@ -1,9 +1,10 @@
+import { serverEnv } from '@/env/server';
 import { NextResponse } from 'next/server';
 import { v4 as uuidv4 } from 'uuid';
 
-const CDN_BASE_UPLOAD_URL = process.env.CDN_BASE_UPLOAD_URL;
-const CDN_BASE_ACCESS_URL = process.env.CDN_BASE_ACCESS_URL;
-const CDN_API_KEY = process.env.CDN_API_KEY!;
+const CDN_BASE_UPLOAD_URL = serverEnv.CDN_BASE_UPLOAD_URL;
+const CDN_BASE_ACCESS_URL = serverEnv.CDN_BASE_ACCESS_URL;
+const CDN_API_KEY = serverEnv.CDN_API_KEY!;
 
 export async function POST(req: Request): Promise<NextResponse> {
   try {
diff --git a/src/components/gmaps-autosuggest.tsx b/src/components/gmaps-autosuggest.tsx
index 761031c6..d6e6b76e 100644
--- a/src/components/gmaps-autosuggest.tsx
+++ b/src/components/gmaps-autosuggest.tsx
@@ -1,5 +1,6 @@
 import Script from 'next/script';
 import { Input } from './ui/input';
+import { clientEnv } from '@/env/client';
 
 export type TgmapsAddress = { city: string; fullAddress: string };
 
@@ -26,7 +27,7 @@ export function GmapsAutocompleteAddress({ form }: { form: any }) {
   return (
     <>
       <Script
-        src={`https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_MAPS_API_KEY}&libraries=places`}
+        src={`https://maps.googleapis.com/maps/api/js?key=${clientEnv.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY}&libraries=places`}
         strategy="lazyOnload"
         onLoad={initializeGmaps}
       />
diff --git a/src/env.ts b/src/env.ts
deleted file mode 100644
index b7ef3fc0..00000000
--- a/src/env.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { createEnv } from '@t3-oss/env-nextjs';
-import { z } from 'zod';
-
-export const env = createEnv({
-  server: {
-    DATABASE_URL: z.string().min(1),
-    POSTGRES_URL: z.string().min(1),
-    POSTGRES_HOST: z.string().min(1),
-    POSTGRES_USERNAME: z.string().min(1),
-    POSTGRES_PASSWORD: z.string().min(1),
-    NEXTAUTH_SECRET: z.string().min(1),
-    NEXTAUTH_URL: z.string().url(),
-  },
-  client: {},
-  // Specify the runtimeEnv manually for both server and client variables
-  runtimeEnv: {
-    DATABASE_URL: process.env.DATABASE_URL,
-    POSTGRES_URL: process.env.POSTGRES_URL,
-    POSTGRES_HOST: process.env.POSTGRES_HOST,
-    POSTGRES_USERNAME: process.env.POSTGRES_USERNAME,
-    POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD,
-    NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
-    NEXTAUTH_URL: process.env.NEXTAUTH_URL,
-  },
-});
diff --git a/src/env/client.ts b/src/env/client.ts
new file mode 100644
index 00000000..da171532
--- /dev/null
+++ b/src/env/client.ts
@@ -0,0 +1,13 @@
+// client-env.ts
+import { createEnv } from '@t3-oss/env-nextjs';
+import { z } from 'zod';
+
+export const clientEnv = createEnv({
+  client: {
+    NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: z.string().min(1),
+  },
+  runtimeEnv: {
+    NEXT_PUBLIC_GOOGLE_MAPS_API_KEY:
+      process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY,
+  },
+});
diff --git a/src/env/server.ts b/src/env/server.ts
new file mode 100644
index 00000000..7c33021c
--- /dev/null
+++ b/src/env/server.ts
@@ -0,0 +1,38 @@
+// server-env.ts
+import { createEnv } from '@t3-oss/env-nextjs';
+import { z } from 'zod';
+
+export const serverEnv = createEnv({
+  server: {
+    DATABASE_URL: z.string().url(),
+    NEXTAUTH_SECRET: z.string().min(1),
+    NEXTAUTH_URL: z.string().url(),
+    POSTGRES_URL: z.string().url(),
+    POSTGRES_HOST: z.string().min(1),
+    POSTGRES_USERNAME: z.string().min(1),
+    POSTGRES_PASSWORD: z.string().min(1),
+    AWS_S3_REGION: z.string().min(1),
+    AWS_S3_ACCESS_KEY_ID: z.string().min(1),
+    AWS_S3_SECRET_ACCESS_KEY: z.string().min(1),
+    AWS_S3_BUCKET_NAME: z.string().min(1),
+    CDN_API_KEY: z.string().min(1),
+    CDN_BASE_UPLOAD_URL: z.string().url(),
+    CDN_BASE_ACCESS_URL: z.string().url(),
+  },
+  runtimeEnv: {
+    DATABASE_URL: process.env.DATABASE_URL,
+    NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
+    NEXTAUTH_URL: process.env.NEXTAUTH_URL,
+    POSTGRES_URL: process.env.POSTGRES_URL,
+    POSTGRES_HOST: process.env.POSTGRES_HOST,
+    POSTGRES_USERNAME: process.env.POSTGRES_USERNAME,
+    POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD,
+    AWS_S3_REGION: process.env.AWS_S3_REGION,
+    AWS_S3_ACCESS_KEY_ID: process.env.AWS_S3_ACCESS_KEY_ID,
+    AWS_S3_SECRET_ACCESS_KEY: process.env.AWS_S3_SECRET_ACCESS_KEY,
+    AWS_S3_BUCKET_NAME: process.env.AWS_S3_BUCKET_NAME,
+    CDN_API_KEY: process.env.CDN_API_KEY,
+    CDN_BASE_UPLOAD_URL: process.env.CDN_BASE_UPLOAD_URL,
+    CDN_BASE_ACCESS_URL: process.env.CDN_BASE_ACCESS_URL,
+  },
+});