Skip to content

Bug: guessPotentiallyProxiedOrySdkUrl Returns Wrong SDK Url for Staging (nextJS) #572

@harleyharl

Description

@harleyharl

Preflight checklist

Ory Network Project

No response

Describe the bug

I have run into an issue with the ory/nextjs package, specifically the getLoginFlow function:

export async function getLoginFlow(

We call this function when a user navigates to the login page of our site.

Under the hood it uses this function to determine the ory SDK Url:

export function guessPotentiallyProxiedOrySdkUrl(options?: {

In Vercel we have a production and a staging environment. This works fine for our production environment. But in our staging environment the user is sent to the wrong link, e.g. xyz.vercel.app because the logic in this function causes the us to hit this line which sets our sdk url as the incorrect address:

    if (!isProduction() && process.env.VERCEL_URL) {
      return `https://${process.env.VERCEL_URL}`.replace(/\/$/, "")
    }

But we need the request to be directed to the address we set with this variable, even in staging: NEXT_PUBLIC_ORY_SDK_URL

Always very grateful for your help and continued support 🙏

Reproducing the bug

  1. Clone this example project https://github.com/ory/elements/tree/main/examples/nextjs-app-router
  2. Publish to Github
  3. Link the project in vercel and create a project from main branch.
  4. GIve the project an additional custom environment called "staging".
  5. Set the environment variable for each environment NEXT_PUBLIC_ORY_SDK_URL as any value.
  6. The login flow will work for production environment but fail for staging environment, with users being directed to xyz.vercel.app when they initiate a login sequence

Relevant log output

Relevant configuration

Version

1.0.0-rc.0

On which operating system are you observing this issue?

None

In which environment are you deploying?

None

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions