Next.js Discord

Discord Forum

Auth0's UserProvider with app/ directory

Unanswered
Red-tailed wasp posted this in #help-forum
Open in Discord
Red-tailed waspOP
Hello guys, I'm rewriting my company's whole React application onto NextJS 13.4.8 using app/ directory. We are using Auth0 as an auth provider (without NextAuth) and from the documentation of the nextjs-auth with app router (currently in beta, https://github.com/auth0/nextjs-auth0/tree/beta#app-router) I assume it should work... somehow. As of now, it is a plain NextJS app so it's an open sandbox.

I've done the following:
* created app/api/auth/[auth0]/route.ts with export const GET = handleAuth(); inside
* wrapped RootLayout with UserProvider from @auth0/nextjs-auth0/client (with <html> and <body> inside
* on login page I'm returning <a href='/api/auth/login' - 'use client' is present there
* inside .env.local there are: AUTH0_SECRET, AUTH0_BASE_URL, AUTH0_ISSUER_BASE_URL, AUTH0_CLIENT_ID and AUTH0_CLIENT_SECRET taken from the Auth0 dashboard - this data is the same as in the old React app

The problem is that the app itself compiles but when going to the browser I'm having the following error:
- error TypeError: Cannot read properties of undefined (reading 'auth0')
at eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@auth0+nextjs-auth0@2.6.3_next@13.4.8/node_modules/@auth0/nextjs-auth0/dist/handlers/auth.js:49:47)
blah blah

Is there something wrong with my solution, or there is a bug in this integration, or maybe there is some other problem that you see here?

Would kindly ask for any help 😇

2 Replies

Russian Toy
i am having the same issue than you, it seems that autho is conflicting with the app directory as it expects _app file in the old fashion. Have you found any solution to this yet?
Russian Toy
solution found here in case someone is having same issue https://github.com/auth0/nextjs-auth0/issues/1309