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

You forgot to wrap your app in <UserProvider> #1612

Open
6 tasks done
Kvek opened this issue Dec 19, 2023 · 1 comment
Open
6 tasks done

You forgot to wrap your app in <UserProvider> #1612

Kvek opened this issue Dec 19, 2023 · 1 comment

Comments

@Kvek
Copy link

Kvek commented Dec 19, 2023

Checklist

Description

Same as this #1557.

Hi,
I setup a new Next.js project (v14) and have been getting this error after following this guide up to this step.

Any help is appreciated. Thanks 😁

Reproduction

Set up a new app.
npx create-next-app auth0-app

Install dependencies
npm install @auth0/nextjs-auth0

Add .env.local with the correct appropriate values

AUTH0_SECRET='use [openssl rand -hex 32] to generate a 32 bytes value'
AUTH0_BASE_URL='http://localhost:3000'
AUTH0_ISSUER_BASE_URL='https://{yourDomain}'
AUTH0_CLIENT_ID='{yourClientId}'
AUTH0_CLIENT_SECRET='{yourClientSecret}'

Add app/api/auth/[auth0]/route.ts

import { handleAuth } from '@auth0/nextjs-auth0';

export const GET = handleAuth();

Add UseProvider

import { UserProvider } from '@auth0/nextjs-auth0/client';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <UserProvider>
        <body>{children}</body>
      </UserProvider>
    </html>
  );
}

Run the app

npm run dev

See this in the browser console.

Screenshot 2023-12-19 at 09 37 53

Additional context

package.json

{
  "name": "auth0-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@auth0/nextjs-auth0": "^3.5.0",
    "next": "14.0.4",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.0.4",
    "typescript": "^5"
  }
}

layout.tsx

import { UserProvider } from '@auth0/nextjs-auth0/client';
import { ReactNode } from 'react';

export default async function RootLayout({ children }:{children:ReactNode}) {
  return (
    <html lang="en">
      <UserProvider>
        <body>{children}</body>
      </UserProvider>
    </html>
  );
}

nextjs-auth0 version

@auth0/nextjs-auth0: "^3.5.0",

Next.js version

next: "14.0.4",

Node.js version

v20.10.0

@Kvek
Copy link
Author

Kvek commented Dec 19, 2023

Tried this guide as well- https://developer.auth0.com/resources/guides/web-app/nextjs/basic-authentication.

Getting the same issue.

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

1 participant