Keep getting "NEXTAUTH_URL: [ 'String must contain at least 1 character(s)' ]"

I'm building a deployment workflow and I keep getting this error. The documentation states that setting this variable is unnecessary when deploying to Vercel, which is what I'm trying to do. Both setting and not setting the variable are things that I have tried. This is my 'env.mjs' file
import { z } from "zod";

const server = z.object({
DATABASE_URL: z.string().url(),
NODE_ENV: z.enum(["development", "test", "production"]),
NEXTAUTH_SECRET:
process.env.NODE_ENV === "production"
? z.string().min(1)
: z.string().min(1).optional(),
NEXTAUTH_URL: z.preprocess(
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// Since NextAuth.js automatically uses the VERCEL_URL if present.
(str) => process.env.VERCEL_URL ?? str,
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string().min(1) : z.string().url(),
),
GOOGLE_CLIENT_ID: z.string(),
GOOGLE_CLIENT_SECRET: z.string(),
});

const client = z.object(
/** @satisfies {Record<`NEXT_PUBLIC_${string}`, import('zod').ZodType>} */ (
{
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
}
),
);

const processEnv = {
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
};
import { z } from "zod";

const server = z.object({
DATABASE_URL: z.string().url(),
NODE_ENV: z.enum(["development", "test", "production"]),
NEXTAUTH_SECRET:
process.env.NODE_ENV === "production"
? z.string().min(1)
: z.string().min(1).optional(),
NEXTAUTH_URL: z.preprocess(
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// Since NextAuth.js automatically uses the VERCEL_URL if present.
(str) => process.env.VERCEL_URL ?? str,
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string().min(1) : z.string().url(),
),
GOOGLE_CLIENT_ID: z.string(),
GOOGLE_CLIENT_SECRET: z.string(),
});

const client = z.object(
/** @satisfies {Record<`NEXT_PUBLIC_${string}`, import('zod').ZodType>} */ (
{
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
}
),
);

const processEnv = {
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
};
I only changed the provider to Google, but there is a slight chance that I destroyed it.
3 Replies
ceespert
ceespertOP2y ago
NEXTAUTH_URL:
process.env.NODE_ENV === "production"
? z.string().optional()
: z.string().url(),
NEXTAUTH_URL:
process.env.NODE_ENV === "production"
? z.string().optional()
: z.string().url(),
I put this in the config file for now, so that it builds. Honestly, I have no idea what it does and it is probably wrong, but at least my workflow.. "works" for now.
Alejo
Alejo2y ago
You can just set it to http://localhost:3000 or whatever port you are using locally
haitam
haitam2y ago
You can set it to the NEXT_APP
Want results from more Discord servers?
Add your server