New Build Redirects to Login Page After Authentication Issue

I’m encountering an issue with my Next.js 14 project deployed on Vercel, using Supabase for authentication. The problem started after initiating a new build for a recent PR, despite no changes to the authentication-related code or even without any change. Here’s the detailed situation:

Issue Description:

  • Old Build Behavior: The older build (from three days ago) works perfectly in production, staging, and the old preview link. Authentication functions as expected, and users remain logged in after login.
  • New Build Behavior: After deploying the new build for the PR, users are redirected to the login page immediately after logging in. This occurs in the preview environment of the new build.
  • Code Changes: No code changes were made in the PR(empty commit) so that The issue seems tied to the new build process itself.

Steps Taken:

  1. Verified that the older builds (production, staging, and old previews) are working correctly.
  2. Confirmed no changes were made to authentication logic or Supabase integration in the recent PR.
  3. Ensured Supabase settings and environment variables remain consistent across builds.

Environment Details:

  • Framework: Next.js 14
  • Hosting: Vercel
  • Auth Provider: Supabase
  • Build Status: Old builds work fine, new build preview exhibits the issue.

Request for Assistance:

I’m looking for help in diagnosing the cause of this issue and resolving it.
I would appreciate any guidance or suggestions on where to look or what to test.

Hi @samurait, welcome to the Vercel Community!

I’m sorry that you’re facing this issue.

Can you confirm if the npm package version for either Supabase or Next changed between the releases?

When the users are sent to the login page after logging in, is their new logged in session valid or are they being logged out right after logging in, which in turn redirects them to the login page?

Can you check the diff between the releases to see if there are any new redirects or navigation logic implemented?

@anshumanb

Can you confirm if the npm package version for either Supabase or Next changed between the releases?

No, nothing has changed. If I build from the currently running version with an empty commit, it no longer works.

When the users are sent to the login page after logging in, is their new logged in session valid or are they being logged out right after logging in, which in turn redirects them to the login page?

The session is valid right after logging in, but when transitioning to another page, the session becomes invalid.

Can you check the diff between the releases to see if there are any new redirects or navigation logic implemented?

There are no differences. Even if I push an empty commit, the new preview fails—while the build itself succeeds, the login session cannot be maintained.

Thanks for providing additional information.

Because it’s a not build issue but runtime issue can you share your public repo or a minimal reproducible example? That will let us all work together from the same code to figure out what’s going wrong.

@anshumanb
This is a private repository, so it’s difficult to provide a reproducible example as I’m unsure of the exact cause. However, I can share vercel account if needed for troubleshooting.

@anshumanb
This issue is critical because it prevents me from redeploying without breaking the application, which would significantly impact my customers. As a result, I’m unable to deliver new features, and the impact on my service is substantial. I’m eager to resolve this as soon as possible and am willing to schedule an online meeting to address the problem directly.

Hi @samurait, I’m sorry that it’s a blocker for you. Can you share the deployment ID that works?

I’ll see if the logs are of any help. But otherwise without a reproducible code it’s hard to debug runtime issues.

empty-commit branch: 3n51rot0d (it doesn’t work propery)
old-pr’s deploymnet: gpmcvv27x (which works right now)

These branches have no differences between the code. However, the deployment for 3n51rot0d fails to build/run properly, while the older deployment from gpmcvv27x is functioning as expected.

Hi @samurait, it looks like your project is using a deprecated Supabase integration. Can you try moving to the new Supabase integration?

Apart from that I don’t think I’d be able to suggest anything else in terms of code fixes without looking at the code.

1 Like

Okay, but this doesn’t seem related… We’ll need to switch to another platform…

The issue seems to be related to Vercel’s build process, as I didn’t make any changes to the code, yet the new build triggered by an empty commit started causing problems…

Hi @samurait, can you confirm if the Supabase and Next.js version stable between the builds? You can do so by using exact version numbers in the package.json because if the application code didn’t change then Vercel’s build would also not change anything else on its own.

@anshumanb

I attempted to run yarn install --immutable, but it didn’t work. It was functioning properly until yesterday, so I suspect something has changed. It seems there have been updates to the build process or related configurations.

Note: It works properly on my local setup, and Vercel was functioning perfectly until yesterday. However, I discovered today that it has suddenly stopped working.

Note: The current versions of staging and production are functioning properly. However, redeploying triggers the issue I’m encountering now. This doesn’t seem to be related to Supabase or any similar service, as an older version of the deployment works fine. Even with an empty commit (no code changes), simply redeploying causes the problem. I strongly suspect that something has changed during the build process or on Vercel’s hosting environment.

Hi @samurait, I understand that this issue seems out of nowhere. But, it’s hard to confirm if it’s a Vercel issue without a reproducible project.

Are you still facing the issue? If so, could you please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.

1 Like

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