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

Need some clarity on how to use the library with server and client components #10720

Closed
a0m0rajab opened this issue Apr 24, 2024 · 4 comments
Closed
Labels
documentation Relates to documentation

Comments

@a0m0rajab
Copy link

What is the improvement or update you wish to see?

Looking into this page: https://authjs.dev/getting-started/session-management/get-session. The app router has an explanation only for the server component without mentioning how to use client components.

It would be great if the client component is explained here and mentioned that the auth() function can only be used for the server (it's written somewhere in previous issues).

Is there any context that might help us understand?

This would be helpful for those who wants to use authjs immediately without going through v4, in migration guide it's explained on how to use both server and client components but it's not mentioned in the main docs. Which would be helpful to get that.

Does the docs page already exist? Please link to it.

No response

@a0m0rajab a0m0rajab added documentation Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Apr 24, 2024
@a0m0rajab
Copy link
Author

a0m0rajab commented Apr 24, 2024

Mentioning the examples would be helpful as well: https://github.com/nextauthjs/next-auth-example
Might be related to: #10724

@ndom91
Copy link
Member

ndom91 commented Apr 26, 2024

Yeah good call. We really wanted to recommend server component usage, although its still possible to use the existing next-auth/react exports like previously (v4). See for example the Sign in / sign out tab from the page you linked that includes a short client-side exaple. Remember for client-side usage you'll need to wrap your component with a <SessionProvider /> somewhere above it

The idea is to grab the session, trigger signin/signout, server side. And then pass any info, like the session, down to client components via props, for example.

But we can definitely make that more clear, while also showing a good example for client-side usage.

@ndom91
Copy link
Member

ndom91 commented Apr 26, 2024

In addition, the example app has a client-component example as well. See apps/examples/nextjs/app/client-example/page.tsx.

@ndom91 ndom91 removed the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Apr 26, 2024
@balazsorban44
Copy link
Member

As Nico mentions, nothing has changed in how you use NextAuth.js in Client components/Pages Router compared to v4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Relates to documentation
Projects
None yet
Development

No branches or pull requests

3 participants