Skip to content

Commit

Permalink
Docs: passing user from Server Component (#1578)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath committed Nov 23, 2023
2 parents 6123230 + 858b3d1 commit f8a2558
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/client/use-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type UserFetcher = (url: string) => Promise<UserProfile | undefined>;
/**
* Configure the {@link UserProvider} component.
*
* If you have any server-side rendered pages (using `getServerSideProps`), you should get the
* If you have any server-side rendered pages (using `getServerSideProps` or Server Components), you should get the
* user from the server-side session and pass it to the `<UserProvider>` component via the `user`
* prop. This will prefill the {@link useUser} hook with the {@link UserProfile} object.
* For example:
Expand All @@ -92,6 +92,29 @@ type UserFetcher = (url: string) => Promise<UserProfile | undefined>;
* }
* ```
*
* or
*
* ```js
* // app/layout.js
* import { UserProvider } from '@auth0/nextjs-auth0/client';
*
* export default async function RootLayout({ children }) {
* // this will emit a warning because Server Components cannot write to cookies
* // see https://github.com/auth0/nextjs-auth0#using-this-sdk-with-react-server-components
* const session = await getSession();
*
* return (
* <html lang="en">
* <body>
* <UserProvider user={session?.user}>
* {children}
* </UserProvider>
* </body>
* </html>
* );
* }
* ```
*
* In client-side rendered pages, the {@link useUser} hook uses a {@link UserFetcher} to fetch the
* user from the profile API route. If needed, you can specify a custom fetcher here in the
* `fetcher` option.
Expand Down

0 comments on commit f8a2558

Please sign in to comment.