environment variables in middleware??

These are the only environment variables I see in middleware
4 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
devagr
devagrOP3y ago
ohh fuck, this doesn't work well with how ct3a has setup environment variables
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
JulieCezar
JulieCezar3y ago
Only the server schema variables are visible in middleware So all you have in /env/schema.mjs in this part below, will be available on middleware For example:
export const serverSchema = z.object({
DATABASE_URL: z.string().url(),
NODE_ENV: z.enum(["development", "test", "production"]),
NEXTAUTH_SECRET: z.string(),
NEXTAUTH_URL: z.preprocess(
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// Since NextAuth automatically uses the VERCEL_URL if present.
(str) => process.env.VERCEL_URL ?? str,
// VERCEL_URL doesnt include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string() : z.string().url()
),
GOOGLE_CLIENT_ID: z.string(),
GOOGLE_CLIENT_SECRET: z.string(),
...
});
export const serverSchema = z.object({
DATABASE_URL: z.string().url(),
NODE_ENV: z.enum(["development", "test", "production"]),
NEXTAUTH_SECRET: z.string(),
NEXTAUTH_URL: z.preprocess(
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// Since NextAuth automatically uses the VERCEL_URL if present.
(str) => process.env.VERCEL_URL ?? str,
// VERCEL_URL doesnt include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string() : z.string().url()
),
GOOGLE_CLIENT_ID: z.string(),
GOOGLE_CLIENT_SECRET: z.string(),
...
});
And you will get the error you posted if the .env file doesn't contain all the vars you specified in the schema, or if they are of incorrect type
Want results from more Discord servers?
Add your server