Add getMemberData hook to SSO organizationProvisioning for customizing member creation #2833

Closed
opened 2026-03-13 10:22:55 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @lkhari on GitHub (Feb 6, 2026).

Is this suited for github?

  • Yes, this is suited for github

When using organizationProvisioning for auto-assigning users to organizations via SSO, there's currently no way to customize the member data before it's created. This is problematic when:

  1. The member table has additionalFields with required: true
  2. You need to populate those fields from SSO provider claims (name, department, etc.)
  3. The default member creation only includes: organizationId, userId, role, createdAt

Current Limitation

The organizationProvisioning config only allows:

  • disabled: boolean
  • defaultRole: string
  • getRole: function to determine role

But there's no way to add custom data to the member record during creation.

Describe the solution you'd like

dd a getMemberData hook to organizationProvisioning that allows customizing member data before creation:

sso({
  organizationProvisioning: {
    disabled: false,
    defaultRole: "member",
    getRole: async ({ user, userInfo, provider }) => {
      // Determine role based on claims
      return userInfo.admin ? "admin" : "member";
    },
    
    // NEW: getMemberData hook
    getMemberData: async ({
      user,
      userInfo,
      token,
      provider,
      organization,
      defaultData,
    }) => {
      // Return additional fields for the member record
      return {
        name: userInfo.name || userInfo.given_name || user.email,
        email: userInfo.email,
        department: userInfo.department,
        // Any other fields from your member schema
      };
    },
  },
})

Describe alternatives you've considered

none

Additional context

  1. TypeScript types: Need to update SSOOptions type to include the new hook
  2. Documentation: Should document that userInfo content varies by provisioning path
  3. Error handling: Should handle cases where hook throws or returns invalid data
  4. Backwards compatibility: This is an additive change, no breaking changes
Originally created by @lkhari on GitHub (Feb 6, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. When using `organizationProvisioning` for auto-assigning users to organizations via SSO, there's currently no way to customize the member data before it's created. This is problematic when: 1. The member table has `additionalFields` with `required: true` 2. You need to populate those fields from SSO provider claims (name, department, etc.) 3. The default member creation only includes: `organizationId`, `userId`, `role`, `createdAt` ### Current Limitation The `organizationProvisioning` config only allows: - `disabled`: boolean - `defaultRole`: string - `getRole`: function to determine role But there's no way to add custom data to the member record during creation. ### Describe the solution you'd like dd a `getMemberData` hook to `organizationProvisioning` that allows customizing member data before creation: ```typescript sso({ organizationProvisioning: { disabled: false, defaultRole: "member", getRole: async ({ user, userInfo, provider }) => { // Determine role based on claims return userInfo.admin ? "admin" : "member"; }, // NEW: getMemberData hook getMemberData: async ({ user, userInfo, token, provider, organization, defaultData, }) => { // Return additional fields for the member record return { name: userInfo.name || userInfo.given_name || user.email, email: userInfo.email, department: userInfo.department, // Any other fields from your member schema }; }, }, }) ``` ### Describe alternatives you've considered none ### Additional context 1. **TypeScript types**: Need to update `SSOOptions` type to include the new hook 2. **Documentation**: Should document that `userInfo` content varies by provisioning path 3. **Error handling**: Should handle cases where hook throws or returns invalid data 4. **Backwards compatibility**: This is an additive change, no breaking changes
GiteaMirror added the enhancement label 2026-03-13 10:22:56 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Feb 6, 2026):

It sounds like you're looking to add a getMemberData hook to your SSO organization provisioning setup in Better Auth, which would allow for customization of member data before it's created. This feature indeed aims to enhance how member data is processed and can help populate necessary fields from SSO claims.

Currently, however, there isn’t a built-in getMemberData hook in the existing documentation or capabilities of Better Auth as of my last update. There is an open issue requesting similar functionality which acknowledges the need for enhanced customization during member creation in the organization provisioning context, particularly addressing scenarios where additional fields are required [1].

For your next steps, I recommend the following:

  1. Keep an eye on any updates related to the open issue mentioned.
  2. Possibly iterate on a custom implementation if immediate functionality is necessary, such as using existing organization hooks.

Feel free to tag members of the Better Auth team, Beka and Max, @bekacru and @ping__, for more insights or updates regarding your request.

What specific fields do you plan to populate in the getMemberData function? This could help refine the implementation details further!

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Feb 6, 2026): It sounds like you're looking to add a `getMemberData` hook to your SSO organization provisioning setup in Better Auth, which would allow for customization of member data before it's created. This feature indeed aims to enhance how member data is processed and can help populate necessary fields from SSO claims. Currently, however, there isn’t a built-in `getMemberData` hook in the existing documentation or capabilities of Better Auth as of my last update. There is an open issue requesting similar functionality which acknowledges the need for enhanced customization during member creation in the organization provisioning context, particularly addressing scenarios where additional fields are required [[1]](https://github.com/better-auth/better-auth/issues/6598). For your next steps, I recommend the following: 1. Keep an eye on any updates related to the open issue mentioned. 2. Possibly iterate on a custom implementation if immediate functionality is necessary, such as using existing organization hooks. Feel free to tag members of the Better Auth team, Beka and Max, @bekacru and @ping__, for more insights or updates regarding your request. What specific fields do you plan to populate in the `getMemberData` function? This could help refine the implementation details further! _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@ping-maxwell commented on GitHub (Feb 11, 2026):

Hello all, we're moving all feature requests or enhancement issues over to Github Discussions.

I've went ahead and created the discussion here:

https://github.com/better-auth/better-auth/discussions/7920

@ping-maxwell commented on GitHub (Feb 11, 2026): Hello all, we're moving all feature requests or enhancement issues over to Github Discussions. I've went ahead and created the discussion here: https://github.com/better-auth/better-auth/discussions/7920
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2833