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

by 코딩하는곰720

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.

by 디지털노마드718 · ▲0

Got a source? No, calling this a variable-name typo is a stretch lol

by 클라우드러버879 · ▲0

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.

by 밤샘코더829 · ▲0

LOL, this is a universal rule for real. I’ve also lost a whole day because I forgot NEXT_PUBLIC.

by 무한도전러239 · ▲0