Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: inconsistent behavior between create-t3-app and NextAuth #2013

Open
zhouzi opened this issue Nov 5, 2024 · 0 comments
Open

bug: inconsistent behavior between create-t3-app and NextAuth #2013

zhouzi opened this issue Nov 5, 2024 · 0 comments

Comments

@zhouzi
Copy link

zhouzi commented Nov 5, 2024

Provide environment information

System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 140.14 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v18.17.0/bin/yarn
npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
pnpm: 9.1.0 - ~/.nvm/versions/node/v18.17.0/bin/pnpm
bun: 1.0.24 - ~/.bun/bin/bun

Describe the bug

create-t3-app favors process.env.VERCEL_URL over process.env.NEXTAUTH_URL:

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() : z.string().url(),
),

But NextAuth favors process.env.NEXTAUTH_URL over process.env.VERCEL_URL:

baseUrl: parseUrl(process.env.NEXTAUTH_URL ?? process.env.VERCEL_URL).origin,

I have set NEXTAUTH_URL to the proper URL on Vercel, but my env was referring to the deployment's domain instead of what I provided. It was very confusing because it was working fine for NextAuth but not in my code.

Reproduction repo

/

To reproduce

  1. Setup a new create-t3-app
  2. Set Vercel's NEXTAUTH_URL to an URL
  3. Log that somewhere
  4. Deploy
  5. Notice how NEXTAUTH_URL is not what you provided to Vercel but VERCEL_URL

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant