Partial session changes
Change selected session fields without rebuilding the entire session object.
Auth.js · Function
unstable_update asynchronously updates session data using a partial session-shaped input. It resolves to the resulting Session or null.
unstable_update accepts a partial Session value, including partial user data, and returns a promise resolving to the updated Session or null. In a Next.js integration, import the helper from the configured auth module and call it with the fields to change.
unstable_update: (data) => Promise<null | Session>;| Name | Type | Description |
|---|---|---|
data | Partial<Session | { user: Partial<undefined | User> }> | Partial session data, optionally containing partial user data. |
Promise<null | Session>
import { auth, unstable_update } from "@/auth";
export async function updateSessionTheme(theme: "light" | "dark") {
return unstable_update({ user: { theme } });
}Pass a partial session-shaped object to update the current session and receive the resulting session or null.
Change selected session fields without rebuilding the entire session object.
Update user-related session data by passing a partial user object.
Handle the result of a session mutation in asynchronous server-side code.
unstable_update is an asynchronous helper whose input is a partial Session value, optionally including partial user data. It resolves to either a Session or null.
Follow-up: What should a caller do with the result? Await the promise and account for the null branch before reading session fields.
Its argument can contain only the session properties that need changing rather than a complete Session object. The documented user shape is also partial, allowing selected user fields to be supplied.
Follow-up: Why is a partial input useful? It avoids requiring callers to reconstruct unrelated session data when changing one field.
The reference documents unstable_update as a Next.js API and gives the signature unstable_update: (data) => Promise<null | Session>. It is therefore used through the Next.js Auth.js integration rather than treated as a synchronous primitive.
Follow-up: What integration should be checked before using it? Confirm that the application is using the current Next.js Auth.js package and its configured auth export.
SessionUserauthNextAuth.js