My login worked locally and sent everyone to the wrong page in production
A missing environment variable didn't crash anything. It just quietly fell back to the homepage.
Learn · Nov 2, 2026
I fixed a login bug today that wasn't a bug in the code. Users signed in, and then landed on the homepage instead of their dashboard.
The code was fine. It worked on my machine every single time. That's what made it annoying.
Here's the thing: the setting that sent people to the dashboard lived in one place, and production looked in another. Same app, two environments, one quiet gap between them.
This one is about The Automated CMO. It's small. But I'd bet you'll hit the same gap on your own build.
The symptom: login worked, but the landing was wrong
Sign-in itself was fine. Clerk authenticated the user, no errors, nothing red. The problem was where people ended up afterward. They should have gone to the dashboard. In production they went to the homepage. No error means no stack trace to chase. A wrong destination is a config problem until proven otherwise, so that's where I started.
The cause: a setting that only existed on my laptop
The redirect relied on an environment variable, NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL. It was in my .env.local file. It was not in Vercel. So locally, the variable was set and the redirect worked. In production, the variable didn't exist, and the app fell back to its default: the homepage. Nothing broke. The app just quietly did the default thing. That's the pattern I keep running into. A missing setting rarely crashes. It falls back.
The second problem hiding behind the first
Fixing the redirect exposed another gap. The homepage nav and footer were hardcoded. They showed the same thing to everyone, so a signed-in user still saw a logged-out page. Even with the right redirect, the site wouldn't have told people they were signed in. Both problems had the same root: I'd built the page for one state and tested one path through it.
The fix: make the app not depend on the missing setting
I changed the code so the redirect to the dashboard no longer relied on that environment variable. I also made the homepage nav and footer check whether someone is signed in and show the signed-in state when they are. I could have just added the variable in Vercel and moved on. That would have fixed today's symptom. But it would leave the app depending on a setting I can forget again on the next project. Code that carries its own default is harder to break.
Why a missing setting fails quietly
Most frameworks treat a missing environment variable as undefined, not as an error. Your code then hits an if statement or a default value and carries on. That's friendly when you're prototyping. It's a trap when you're shipping. The app didn't know anything was wrong. Neither did I. There was no alert, no failed build, no angry log line. The only signal was a person landing somewhere they didn't expect. If a setting matters, the app should say so loudly when it's missing. If it doesn't matter, the app shouldn't depend on it. Anything in between is a bug waiting for a deploy.
The habit I'm keeping
Two environments means two sets of settings. My .env.local is a private file on my machine. Vercel has its own list. Nothing keeps them in sync unless I do. So before I call a feature done, I now compare the names of what the code reads against what production actually has. Names only, never values. The prompt below does that audit for you. It's a boring check. It's also the one that would have caught this before anyone logged in.
Ship it and check the real thing
The change went out as a production deploy on Vercel from the main branch. The build finished and went live without a failed attempt in front of it. A green deploy doesn't prove the fix, though. The proof is signing in on the live site and watching where you land. That's the check I care about, so that's the check I run.
What broke: Production sent signed-in users to the homepage instead of the dashboard. The redirect depended on NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL, which existed in my local .env.local but not in Vercel, so the app fell back to /. The homepage nav and footer were also hardcoded, so signed-in users still saw a logged-out page.
The fix: I stopped the dashboard redirect from depending on that variable, and I made the homepage nav and footer reflect whether someone is signed in. Then I deployed to production and tested the login flow on the live site.
Audit my project for environment variables that exist locally but may be missing in production.
1. List every environment variable the code reads (process.env.*, import.meta.env.*, and any framework-specific config such as auth redirect URLs).
2. Compare that list to the variable NAMES in my .env.local. Never print values.
3. Tell me which names the code reads but are not in .env.local, and which are in .env.local but never read.
4. For each variable, tell me what the app does if it is missing in production: crash, or silently fall back to a default. Flag every silent fallback.
5. For each silent fallback, suggest either a safe default in code or a startup check that fails loudly.
6. Give me a checklist of names to confirm exist in my Vercel project settings. Names only, no values.Get new guides and builds in your inbox
No noise. New artifacts, skills, and lessons when they drop — and early access when agents launch.
Want a full structured path instead of one-off guides?
That's Learn AI with AI — a sequenced course that takes you from zero to building real things, with community and accountability built in.
Check out Learn AI with AI →