UpdateSession: ((...args) => Promise<void>)
Type declaration
- (...args): Promise<void>
Parameters
Rest
...args: [IncomingMessage, ServerResponse, default] | [NextApiRequest, NextApiResponse, default] | [NextRequest, NextResponse, default] | [default]
Returns Promise<void>
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: