Struggling to use VERCEL_URL with `@t3-oss/env-nextjs`

So i am trying to use the VERCEL_URL for my app url however I'm having issue on how to use it and still fullfil the types. my env.mjs
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

export const env = createEnv({
server: {
// .... server items
},
client: {
NEXT_API_APP_TOKEN: z.string().min(1),
NEXT_PUBLIC_APP_URL: z.string().url(),
},
runtimeEnv: {
// App
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
NEXT_API_APP_TOKEN: process.env.NEXT_API_APP_TOKEN,

// ... set all server env's
},
});
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

export const env = createEnv({
server: {
// .... server items
},
client: {
NEXT_API_APP_TOKEN: z.string().min(1),
NEXT_PUBLIC_APP_URL: z.string().url(),
},
runtimeEnv: {
// App
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
NEXT_API_APP_TOKEN: process.env.NEXT_API_APP_TOKEN,

// ... set all server env's
},
});
my nextjs.config.mjs
if (process.env.NODE_ENV === "development") {
process.env.NEXT_PUBLIC_APP_URL = "http://localhost:3000";
}

if (process.env.VERCEL_URL && !process.env.NEXT_PUBLIC_APP_URL) {
process.env.NEXT_PUBLIC_APP_URL = `https://${process.env.VERCEL_URL}`;
}
if (process.env.NODE_ENV === "development") {
process.env.NEXT_PUBLIC_APP_URL = "http://localhost:3000";
}

if (process.env.VERCEL_URL && !process.env.NEXT_PUBLIC_APP_URL) {
process.env.NEXT_PUBLIC_APP_URL = `https://${process.env.VERCEL_URL}`;
}
Solution:
Turns out the solution is to change the turbo config to include the envs
Jump to solution
1 Reply
Solution
Jacob
Jacob5mo ago
Turns out the solution is to change the turbo config to include the envs
Want results from more Discord servers?
Add your server