// Or, it's slightly more efficient to use the `req`, `res` args if you're // using another part of the SDK like `withApiAuthRequired` or `getAccessToken`. import { getSession, withApiAuthRequired } from'@auth0/nextjs-auth0';
Note: You can't write to the cookie in a React Server Component, so updates
to the session like setting the expiry of the rolling session won't be persisted.
For this, we recommend interacting with the session in the middleware.
You can also get the session in a page or route in the Edge Runtime:
Get the user's session from the server.
In the App Router:
In a route handler:
In a page or React Server Component:
Note: You can't write to the cookie in a React Server Component, so updates to the session like setting the expiry of the rolling session won't be persisted. For this, we recommend interacting with the session in the middleware.
You can also get the session in a page or route in the Edge Runtime:
Note: The Edge runtime features are only supported in the App Router.
In the Page Router:
In an API handler:
In a page:
In middleware: