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

v4 - ability to pass user directly to client from server #1823

Closed
5 tasks done
ajwootto opened this issue Nov 22, 2024 · 4 comments
Closed
5 tasks done

v4 - ability to pass user directly to client from server #1823

ajwootto opened this issue Nov 22, 2024 · 4 comments

Comments

@ajwootto
Copy link

Checklist

  • 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.

Describe the problem you'd like to have solved

With v3 we had the "UserProvider" component that accepted a user argument allowing you to pass the user directly from the server to the client without requiring it to make a request back to the server:

const session = getSession()

<UserProvider user={session.user}>
...etc

Now the useUser hook always makes a fetch request, which prevents immediate rendering of content that depends on the current user.

Describe the ideal solution

There should be a built-in option for providing the user that we already have access to in server components on the clientside, rather than making it perform another full round-trip to the server just to get back the same information.

Alternatives and current workarounds

No response

Additional context

No response

@guabu
Copy link
Contributor

guabu commented Nov 24, 2024

Hey @ajwootto, you should be able to serialize and pass the user from the server to your client components. Our documentation has examples of how to do that: https://github.com/auth0/nextjs-auth0/tree/v4?tab=readme-ov-file#on-the-server-app-router

I hope that helps!

@ajwootto
Copy link
Author

Hi @guabu, I know I can definitely do that myself but what I'm suggesting is that the SDK should provide an out-of-the-box "UserProvider" like v3 did, so that the useUser hook doesn't need to make a clientside fetch request to get the info we already have. Right now I've made my own useUser hook that reads from my own custom context rather than use the SDK's built-in method, which seems strange given that this would be a very common use-case for this SDK.

@guabu
Copy link
Contributor

guabu commented Nov 27, 2024

Hey @ajwootto, thanks for clarifying! We plan on adding an <Auth0Provider /> as an abstraction to pass in an initial user (for the useUser() hook) as well as client-side configuration.

Under the hood we use SWR which can be configured by <SWRConfig /> but we wanted to introduce a better abstraction for this rather than leaking the underlying implementation.

@guabu guabu mentioned this issue Dec 1, 2024
@nandan-bhat
Copy link
Contributor

Closing this ticket as this issue has been fixed 4.0.0-beta.9

This was referenced Feb 12, 2025
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