Auth doesn't work in production, but works locally

I created auth for my app with SignJWT from JOSE. Everything works fine locally, it’s been tested over and over. However, in the production version deployed to Vercel, I find none of the auth functions work. None of them. I can’t login (making the entire app useless), can’t reset password, can’t create new account - it won’t do anything. The db is Postgres, also on Vercel (should be simple when everything is on Vercel, right…?).

Depending on the exact function, I typically see either a 500 or 404 error, often a POST error, or GET error. In general, trying to log in, I get a POST 500 error.

Given the database and storage are currently on Vercel, also, I would prefer not to tear this project apart and rebuild with a different database and storage platform, but I don’t understand what Vercel has done that renders this app useless.

I have loaded all environmental variables directly into Vercel. I have tried removing old ones, but the option to do so is grayed out (and I’ve disconnected everything from the project, as advised, so not sure why I can’t remove anything still). I don’t know how Vercel reads these, so don’t know if it’s part of the issue or not.

The errors are generic errors, and only point to the files in the auth folder for the specified action. So I have no further information about any of these errors.

A couple other notes, in trying to troubleshoot this, as mentioned I had to disconnect things from the project. I’ve reconnected GitHub and the Postgres db, however my Blob seems to just have disappeared. I don’t know why it doesn’t show ANYWHERE now, as I only disconnected it and never deleted anything. Also, it seems some of the env variables can be removed now, but only the ones I copied and saved last night in trying to fix this. Yet they are connected. The other ones should NOT be connected, yet have Remove grayed out. Seems backwards. I do what Vercel says I need to do, and then the opposite happens…

I really need help getting this to function properly. I don’t understand why everything works perfectly locally, but as soon as I visit the Vercel deployment, it’s so screwed up I can’t even login to do any further testing.

Framework: Next.js
Authentication: Custom JWT with JOSE
Node v20

Not sure if there’s anything else I should include here, but happy to reply to any further questions. Thank you!

Hey @enlguy. You should not need to manage environment variables manually with Vercel Postgres. The integration creates the variables in your project settings and automatically syncs the values for you.

I often use the runtime logs to investigate issues with a deployment. There’s a lot of info there if you click an log record to expand for more details. Try/catch statements can be very helpful along with these logs.

A 500 is a very generic error, so that’s not much to go on. If there’s an associated error code, like ``, then you can look it up in the Error Codes list to get tips for how to fix it. There should also be a link directly to the troubleshooting tips from the error page if you see one thrown by your project.

The 404 means something is missing or in an unexpected location. I’ve written a longer post with tips for debugging this kind of error. Please give these a try: Debugging 404 Errors

Thanks Amy.

There are only four lines in the runtime logs. Two 200s, and two 307s for redirect. Except nothing is going anywhere, of course.

Nothing should be missing! I know what a 404 is, but again, this all works perfectly locally, and yet it won’t even log me in on the Vercel deployment. There are other issues posted on GitHub about 500 errors with auth on Vercel that works locally, but no one has posted solutions there… In fact, the other guy that raised the issue ended up changing his auth completely because there seemed to be no way to get Vercel to work with SignJWT.

SO, I would really appreciate someone better looking into this, since it’s not just my app, but a recurring theme, and the last time went without solution. I do not want to have to do what the other guy did and recode my whole app for a different authentication method. I already went way out of my way to build a chat feature without websockets because Vercel causes problems with that. Thankfully, that deployed okay, but I’m using Clerk separately for that, which will not be an end solution. In short, if custom JWT solutions simply won’t work with Vercel, I will need to find a new hosting/storage provider.

Also, I’m already using try/catch blocks on the token creation with the login code.

Without seeing your app, I’m not able to dig into the problem enough to offer specific suggestions for your project. Some general advice is to keep in mind that running a project locally in development mode is a bit different from the deployed version of the app. It’s possible that a file isn’t being deployed for some reason, but it would still be present in your local copy of the repo allowing the dev version to work.

I got this example from v0 in case it helps:

https://v0.dev/chat/6ucfDV8Rb1y?b=b_tCo3zO6paFY

If you need someone to look into it more, a minimal reproducible example would give us way to see the problem. It would also be helpful to see the error details in case you see something different from what we see.

This is the repo. GitHub - enlguy/date-main

This is the deployment’s login page: Supaluva

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.