@@ -238,40 +238,86 @@ export interface CallbacksOptions<P = Profile, A = Account> {
238238 * If you want to make something available you added to the token through the `jwt` callback,
239239 * you have to explicitly forward it here to make it available to the client.
240240 *
241- * [Documentation](https://authjs.dev/guides/basics/callbacks#session-callback) |
242- * [`jwt` callback](https://authjs.dev/guides/basics/callbacks#jwt-callback) |
243- * [`useSession`](https://authjs.dev/reference/react/#usesession) |
244- * [`getSession`](https://authjs.dev/reference/utilities/#getsession) |
245- *
241+ * @see [`jwt` callback](https://authjs.dev/reference/core/types#jwt)
246242 */
247- session : ( params : {
248- session : Session
249- user : User | AdapterUser
250- token : JWT
251- } ) => Awaitable < Session >
243+ session : (
244+ params :
245+ | {
246+ session : Session
247+ /** Available when {@link AuthConfig.session} is set to `strategy: "jwt"` */
248+ token : JWT
249+ /** Available when {@link AuthConfig.session} is set to `strategy: "database"`. */
250+ user : AdapterUser
251+ } & {
252+ /**
253+ * Available when using {@link AuthConfig.session} `strategy: "database"` and an update is triggered for the session.
254+ *
255+ * :::note
256+ * You should validate this data before using it.
257+ * :::
258+ */
259+ newSession : any
260+ trigger : "update"
261+ }
262+ ) => Awaitable < Session | DefaultSession >
252263 /**
253264 * This callback is called whenever a JSON Web Token is created (i.e. at sign in)
254265 * or updated (i.e whenever a session is accessed in the client).
255266 * Its content is forwarded to the `session` callback,
256267 * where you can control what should be returned to the client.
257- * Anything else will be kept inaccessible from the client .
268+ * Anything else will be kept from your front-end .
258269 *
259- * Returning `null` will invalidate the JWT session by clearing
260- * the user's cookies. You'll still have to monitor and invalidate
261- * unexpired tokens from future requests yourself to prevent
262- * unauthorized access.
270+ * The JWT is encrypted by default.
263271 *
264- * By default the JWT is encrypted.
265- *
266- * [Documentation](https://authjs.dev/guides/basics/callbacks#jwt-callback) |
267- * [`session` callback](https://authjs.dev/guides/basics/callbacks#session-callback)
272+ * [Documentation](https://next-auth.js.org/configuration/callbacks#jwt-callback) |
273+ * [`session` callback](https://next-auth.js.org/configuration/callbacks#session-callback)
268274 */
269275 jwt : ( params : {
276+ /**
277+ * When `trigger` is `"signIn"` or `"signUp"`, it will be a subset of {@link JWT},
278+ * `name`, `email` and `image` will be included.
279+ *
280+ * Otherwise, it will be the full {@link JWT} for subsequent calls.
281+ */
270282 token : JWT
271- user ?: User | AdapterUser
272- account ?: A | null
283+ /**
284+ * Either the result of the {@link OAuthConfig.profile} or the {@link CredentialsConfig.authorize} callback.
285+ * @note available when `trigger` is `"signIn"` or `"signUp"`.
286+ *
287+ * Resources:
288+ * - [Credentials Provider](https://authjs.dev/reference/core/providers_credentials)
289+ * - [User database model](https://authjs.dev/reference/adapters#user)
290+ */
291+ user : User | AdapterUser
292+ /**
293+ * Contains information about the provider that was used to sign in.
294+ * Also includes {@link TokenSet}
295+ * @note available when `trigger` is `"signIn"` or `"signUp"`
296+ */
297+ account : A | null
298+ /**
299+ * The OAuth profile returned from your provider.
300+ * (In case of OIDC it will be the decoded ID Token or /userinfo response)
301+ * @note available when `trigger` is `"signIn"`.
302+ */
273303 profile ?: P
304+ /**
305+ * Check why was the jwt callback invoked. Possible reasons are:
306+ * - user sign-in: First time the callback is invoked, `user`, `profile` and `account` will be present.
307+ * - user sign-up: a user is created for the first time in the database (when {@link AuthConfig.session}.strategy is set to `"database"`)
308+ * - update event: Triggered by the [`useSession().update`](https://next-auth.js.org/getting-started/client#update-session) method.
309+ * In case of the latter, `trigger` will be `undefined`.
310+ */
311+ trigger ?: "signIn" | "signUp" | "update"
312+ /** @deprecated use `trigger === "signUp"` instead */
274313 isNewUser ?: boolean
314+ /**
315+ * When using {@link AuthConfig.session} `strategy: "jwt"`, this is the data
316+ * sent from the client via the [`useSession().update`](https://next-auth.js.org/getting-started/client#update-session) method.
317+ *
318+ * ⚠ Note, you should validate this data before using it.
319+ */
320+ session ?: any
275321 } ) => Awaitable < JWT | null >
276322}
277323
@@ -451,7 +497,9 @@ export type InternalProvider<T = ProviderType> = (T extends "oauth"
451497 * :::
452498 * - **`"error"`**: Renders the built-in error page.
453499 * - **`"providers"`**: Returns a client-safe list of all configured providers.
454- * - **`"session"`**: Returns the user's session if it exists, otherwise `null`.
500+ * - **`"session"`**:
501+ * - **`GET**`: Returns the user's session if it exists, otherwise `null`.
502+ * - **`POST**`: Updates the user's session and returns the updated session.
455503 * - **`"signin"`**:
456504 * - **`GET`**: Renders the built-in sign-in page.
457505 * - **`POST`**: Initiates the sign-in flow.
0 commit comments