The Bug I Spent 3 Days on Turned Out to Be a Typo
On a side project, API responses kept coming back 401, so I tore through everything from the middleware to the token expiration logic. It worked in Postman but not in the browser. I figured it might be CORS, so I messed with the headers too.
In the end, the cause was a typo in a variable name in the env file. I had written NEXTPUBLIC_API_URL instead of NEXT_PUBLIC_API_URL. Since the prefix wasn't recognized, it was being bundled into the client as undefined.
If the error message had been more helpful, I wouldn't have lost 3 days... We've all dealt with an env typo at least once, right? lol
9 answers
Well, that's a bit... I don't get how it took you three days. If you'd just logged it to the console and taken one look at the request headers, you'd have found it right away. Before you start tearing apart the middleware, get into the habit of checking the Network tab first.
Got a source? No, calling this a variable-name typo is a stretch lol
Ah, I totally relate... with env, one typo really can burn 3 days. But the funny-sad part is, I get that a 401 shows up, but why it shows up is the problem. If the prefix doesn’t get applied, it goes through as undefined, and why that shows up as a 401 is the trap.
LOL, this is a universal rule for real. I’ve also lost a whole day because I forgot NEXT_PUBLIC.