Add authClient.updateSession() method #2903

Closed
opened 2026-03-13 10:26:42 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @ryami333 on GitHub (Feb 20, 2026).

Is this suited for github?

  • Yes, this is suited for github

It's currently possible to specify additionalFields on a session or user, like this:

export const auth = betterAuth({
  session: {
    selectedOrganisation: {
      type: "string",
      required: false,
    }
  },
  user: {
    favoriteColor: {
      type: "string",
      required: false,
    }
  },
};

And, there is a mechanism for updating that value for a user, like:

import { createAuthClient } from "better-auth/react";

const authClient = createAuthClient();

authClient.updateUser({ favoriteColor: "red" });

However, it's not possible to do the same for a session:

// No such method!
authClient.updateSession({ selectedOrganisation: "foo" });

Describe the solution you'd like

Ideally, I'd like to see the authClient.updateSession(…) method added.

Describe alternatives you've considered

I'm aware that this is potentially dangerous – if you can update a session then you can potentially invalidate it. I would like to suggest two potential mitigations:

  1. The method could be called authClient.dangerousUpdateSession to reflect this.
  2. The method could be called authClient.updateSessionAdditionalFields, and its implementation could guard the core session fields against mutation.

Additional context

Related discussions:

Originally created by @ryami333 on GitHub (Feb 20, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. It's currently possible to specify `additionalFields` on a `session` or `user`, like this: ```ts export const auth = betterAuth({ session: { selectedOrganisation: { type: "string", required: false, } }, user: { favoriteColor: { type: "string", required: false, } }, }; ``` And, there is a mechanism for _updating_ that value for a `user`, like: ```ts import { createAuthClient } from "better-auth/react"; const authClient = createAuthClient(); authClient.updateUser({ favoriteColor: "red" }); ``` However, it's *not* possible to do the same for a `session`: ```ts // No such method! authClient.updateSession({ selectedOrganisation: "foo" }); ``` ### Describe the solution you'd like Ideally, I'd like to see the `authClient.updateSession(…)` method added. ### Describe alternatives you've considered I'm aware that this is potentially dangerous – if you can update a session then you can potentially _invalidate_ it. I would like to suggest two potential mitigations: 1. The method could be called `authClient.dangerousUpdateSession` to reflect this. 2. The method could be called `authClient.updateSessionAdditionalFields`, and its implementation could guard the core session fields against mutation. ### Additional context Related discussions: - https://github.com/better-auth/better-auth/discussions/3860 - https://github.com/better-auth/better-auth/discussions/6148
GiteaMirror added the enhancement label 2026-03-13 10:26:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2903