Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.0-beta.12 throws a startsWith error when AUTH0_DOMAIN not set #1849

Closed
6 tasks done
robcaldecott opened this issue Dec 18, 2024 · 3 comments
Closed
6 tasks done

Comments

@robcaldecott
Copy link

robcaldecott commented Dec 18, 2024

Checklist

Description

We have just upgraded from 4.0.0-beta.10 to 4.0.0-beta.12 and our next build inside a docker container is failing for route handlers that call getAccessToken.

We build our app in docker with no env vars set, so all the Auth0 variables will be missing. We then inject these into the container when it actually runs. Until now this has not been an issue.

But with beta.12 the following route handler will cause next build to error:

import { auth0 } from "@/auth0/client";

export function async GET() {
  const session = await auth0.getAccessToken();
  ... 
}

This causes the following error:

Collecting page data  ..TypeError: Cannot read properties of undefined (reading 'startsWith')
    at new rv (.next/server/chunks/8423.js:1:49131)
    at new aR (.next/server/chunks/8423.js:1:95081)
    at 44684 (.next/server/app/api/customers/[id]/route.js:1:4294)
    at t (.next/server/webpack-runtime.js:1:142)
    at 84331 (.next/server/app/api/customers/[id]/route.js:1:1086)
    at t (.next/server/webpack-runtime.js:1:142)
    at t (.next/server/app/api/customers/[id]/route.js:1:4586)
    at <unknown> (.next/server/app/api/customers/[id]/route.js:1:4634)
    at t.X (.next/server/webpack-runtime.js:1:1270)
    at <unknown> (.next/server/app/api/customers/[id]/route.js:1:4599)

I have tied forcing the routes causing this to by dynamic like this:

export const dynamic = "force-dynamic";

But to no avail.

It appears that this happens if AUTH0_DOMAIN is not set at build time. However, if this is set to an empty string then it works. Any ideas how we can handle this? Could the auth0 code check for undefined to handle this?

Reproduction

  • Create a new Next.js app with the auth0 beta.
  • Add a route handler that calls getAccessToken
  • Run next build without setting AUTH0_DOMAIN

Additional context

No response

nextjs-auth0 version

4.0.0-beta.12

Next.js version

15.1

Node.js version

20

@robcaldecott
Copy link
Author

Note that wrapping getAccessToken in try ... catch does not help either. 😢 we still get the error during the build.

@robcaldecott robcaldecott changed the title 4.0.0-beta.12 throws a startWith error when AUTH0_DOMAIN not set 4.0.0-beta.12 throws a startsWith error when AUTH0_DOMAIN not set Dec 18, 2024
@guabu
Copy link

guabu commented Dec 19, 2024

Hey @robcaldecott, this was a regression introduced in 4.0.0-beta.11. Apologies for the inconvenience here, we'll get this resolved in the upcoming release.

For the time being, setting the AUTH0_DOMAIN environment variable as temporary workaround as you mentioned should ensure the build succeeds.

@guabu guabu mentioned this issue Dec 19, 2024
@guabu
Copy link

guabu commented Dec 20, 2024

This should now be fixed in the latest release (4.0.0-beta.13). Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants