Update the session object. The provided session object will replace the existing session.
Note you can't use this method to login or logout - you should use the login and logout handlers for this.
If no session is provided, it doesn't contain a user or the user is not authenticated; this is a no-op.
// Or, it's slightly more efficient to use the `req`, `res` args if you're // using another part of the SDK like `withApiAuthRequired` or `getSession`. import { getSession, updateSession, withApiAuthRequired } from'@auth0/nextjs-auth0';
Update the session object. The provided
session
object will replace the existing session.Note you can't use this method to login or logout - you should use the login and logout handlers for this. If no session is provided, it doesn't contain a user or the user is not authenticated; this is a no-op.
In the App Router:
In a route handler:
In a Server Action 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 would need to happen in a Server Action. More info on Server Actions https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions
You can also update 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: