Open
Description
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
Hi,
In v3, we could easily override user details by updating the user prop within <UserProvider />
. For example:
import { UserProvider } from '@auth0/nextjs-auth0/client'
import { headers } from 'next/headers'
export default async function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const headersList = headers()
const sub = headersList.get('user-id') ?? ''
const email = headersList.get('user-email') ?? ''
const name = headersList.get('user-name') ?? ''
return (
<>
<UserProvider user={{ sub, email, name }}>
{children}
</UserProvider>
</>
)
}
Then in client components, we could then access the overridden user details via useUser()
.
However, in v4, even though we set the user={{ sub, email, name }} prop in <Auth0Provider />
, useUser()
ignores these overridden details and instead returns the default session.user
details.
Reproduction
- In the root layout, set the user prop on
Auth0Provider
with test data:
<Auth0Provider user={{ sub: "test_id", email: "[email protected]", name: "test name" }}>
{children}
</Auth0Provider>
- In a client component, retrieve user details using
useUser()
:
'use client'
import { useUser } from '@auth0/nextjs-auth0'
export default function ClientComponent() {
const { user } = useUser()
console.log('User details:', user)
return (
<>{user?.sub} - {user?.email} - {user?.name}</>
)
}
Additional context
No response
nextjs-auth0 version
4.1.0
Next.js version
14.2.25
Node.js version
18.19.0