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

Passing an intial user from the server to <Auth0Provider user={session?.user}> #1915

Closed
6 tasks done
florisdg opened this issue Feb 13, 2025 · 1 comment
Closed
6 tasks done

Comments

@florisdg
Copy link

Checklist

Description

In v3 I used to have this in my Next.js app with Pages router:

export function App({ Component, pageProps, router }: AppPropsWithLayout) {
  const getLayout = Component.getLayout ?? ((page: ReactNode) => page)

  return <UserProvider user={pageProps.user}>
...

Every page using getServerSideProps was wrapped with withPageAuthRequired, which would populate this a 'user' property in the pageProps.

In v4 this is obviously gone, and in EXAMPLES.md it shows this:

import { Auth0Provider } from "@auth0/nextjs-auth0"

import { auth0 } from "@/lib/auth0"

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode
}>) {
  const session = await auth0.getSession()

  return (
    <html lang="en">
      <body>
        <Auth0Provider user={session?.user}>{children}</Auth0Provider>
      </body>
    </html>
  )
}

However, when I do what the example suggests in a _app.tsx file, or in any of my Layout files it won't work because these files cannot be asynchronous (Here in the Next.js docs you see no async in any of the layout files or _app.tsx.

export function App({ Component, pageProps, router }: AppPropsWithLayout) {
  const getLayout = Component.getLayout ?? ((page: ReactNode) => page)

  const session = await auth0.getSession()

  return <Auth0Provider user={session?.user}>
...

I am clueless how I can get this to work the way it used to, so users do not see a 'flash' of empty content until the useUser() hook has retrieved the user.

Reproduction

Get the same from v3 functionality back in v4's in apps with Page Router

Additional context

No response

nextjs-auth0 version

4.0.1

Next.js version

14.2.23

Node.js version

22.11

@florisdg
Copy link
Author

florisdg commented Feb 13, 2025

sorry, used the wrong template. New issue: #1916

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