[Organization Plugin] Prisma Invalid Invocation for Member Creation #2533

Open
opened 2026-03-13 10:01:13 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @m0L3cuL3 on GitHub (Dec 15, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

     const db = ctx.context.adapter;
          // Try to find org by slug (shop name)
          let organization: any = await db.findOne({
            model: 'organization',
            where: [{ field: 'slug', value: shopName }],
          });

          if (!organization) {
            // Create New Organization
            organization = await db.create({
              model: 'organization',
              data: {
                name: shopName,
                slug: shopName,
                userId: user.id, // Owner
                createdAt: new Date(),
                metadata: JSON.stringify({
                  shopifyAccessToken: accessToken,
                  shopifyApiKey: apiKey,
                }),
                shop: shopDomain,
              },
            });

            // Add Owner Member
            await db.create({
              model: 'member',
              data: {
                organizationId: organization.id,
                userId: user.id,
                role: 'owner',
                createdAt: new Date(),
              },
            });
          } else {
            
            if (accessToken) {
              await db.update({
                model: 'organization',
                where: [{ field: 'id', value: organization.id }],
                update: {
                  metadata: JSON.stringify({
                    shopifyAccessToken: accessToken,
                    shopifyApiKey: apiKey,
                  }),
                },
              });
            }

            const member = await db.findOne({
              model: 'member',
              where: [
                { field: 'organizationId', value: organization.id },
                { field: 'userId', value: user.id },
              ],
            });

            if (!member) {
              await db.create({
                model: 'member',
                data: {
                  organizationId: organization.id,
                  userId: user.id,
                  role: 'member',
                  createdAt: new Date(),
                },
              });
            }
          }

Current vs. Expected behavior

Current Behavior:

  • It throws the PrismaClientValidationError
Invalid `prisma.member.create()` invocation:

{
  data: {
    role: "member",
    createdAt: new Date("2025-12-15T08:12:52.541Z"),
    id: "9CvR23r2bkGI4oa4VswPWcMelSVzPz8b",
+   organization: {
+     create: OrganizationCreateWithoutMembersInput | OrganizationUncheckedCreateWithoutMembersInput,
+     connectOrCreate: OrganizationCreateOrConnectWithoutMembersInput,
+     connect: OrganizationWhereUniqueInput
+   }
  },
  select: undefined
}

Argument `organization` is missing.

Expected Behavior:

  • It should create a member

What version of Better Auth are you using?

1.4.6

System info

"system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 10 Pro",
    "release": "10.0.19045",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5600G with Radeon Graphics         ",
    "totalMemory": "23.37 GB",
    "freeMemory": "4.16 GB"
  },
  "node": {
    "version": "v20.19.5",
    "env": "production"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.8.2"
  },
  "frameworks": [
    {
      "name": "express",
      "version": "^4.21.2"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.12.0"
    }
  ],
  "betterAuth": {
    "version": "^1.4.6",
    "config": {
      "user": {
        "additionalFields": {
          "bio": {
            "type": "string",
            "required": false,
            "input": true
          }
        }
      },
      "emailAndPassword": {
        "enabled": true
      },
      "plugins": [
        {
          "name": "open-api",
          "config": {
            "id": "open-api",
            "endpoints": {}
          }
        },
        {
          "name": "passkey",
          "config": {
            "id": "passkey",
            "endpoints": {},
            "schema": {
              "passkey": {
                "fields": {
                  "name": {
                    "type": "string",
                    "required": false
                  },
                  "publicKey": {
                    "type": "string",
                    "required": true
                  },
                  "userId": {
                    "type": "string",
                    "references": {
                      "model": "user",
                      "field": "id"
                    },
                    "required": true,
                    "index": true
                  },
                  "credentialID": {
                    "type": "string",
                    "required": true,
                    "index": true
                  },
                  "counter": {
                    "type": "number",
                    "required": true
                  },
                  "deviceType": {
                    "type": "string",
                    "required": true
                  },
                  "backedUp": {
                    "type": "boolean",
                    "required": true
                  },
                  "transports": {
                    "type": "string",
                    "required": false
                  },
                  "createdAt": {
                    "type": "date",
                    "required": false
                  },
                  "aaguid": {
                    "type": "string",
                    "required": false
                  }
                }
              }
            },
            "$ERROR_CODES": {
              "CHALLENGE_NOT_FOUND": "Challenge not found",
              "YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY": "You are not allowed to register this passkey",
              "FAILED_TO_VERIFY_REGISTRATION": "Failed to verify registration",
              "PASSKEY_NOT_FOUND": "Passkey not found",
              "AUTHENTICATION_FAILED": "Authentication failed",
              "UNABLE_TO_CREATE_SESSION": "Unable to create session",
              "FAILED_TO_UPDATE_PASSKEY": "Failed to update passkey"
            }
          }
        },
        {
          "name": "shopify-auth",
          "config": {
            "id": "shopify-auth",
            "endpoints": {}
          }
        },
        {
          "name": "custom-session",
          "config": {
            "id": "custom-session",
            "hooks": {
              "after": [
                {}
              ]
            },
            "endpoints": {},
            "$Infer": {
              "Session": {}
            }
          }
        },
        {
          "name": "admin",
          "config": {
            "id": "admin",
            "hooks": {
              "after": [
                {}
              ]
            },
            "endpoints": {},
            "$ERROR_CODES": {
              "FAILED_TO_CREATE_USER": "Failed to create user",
              "USER_ALREADY_EXISTS": "User already exists.",
              "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL": "User already exists. Use another email.",
              "YOU_CANNOT_BAN_YOURSELF": "You cannot ban yourself",
              "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE": "You are not allowed to change users role",
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS": "You are not allowed to create users",
              "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS": "You are not allowed to list users",
              "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS": "You are not allowed to list users sessions",
              "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS": "You are not allowed to ban users",
              "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS": "You are not allowed to impersonate users",
              "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS": "You are not allowed to revoke users sessions",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS": "You are not allowed to delete users",
              "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD": "[REDACTED]",
              "BANNED_USER": "You have been banned from this application",
              "YOU_ARE_NOT_ALLOWED_TO_GET_USER": "You are not allowed to get user",
              "NO_DATA_TO_UPDATE": "No data to update",
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS": "You are not allowed to update users",
              "YOU_CANNOT_REMOVE_YOURSELF": "You cannot remove yourself",
              "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE": "You are not allowed to set a non-existent role value",
              "YOU_CANNOT_IMPERSONATE_ADMINS": "You cannot impersonate admins"
            },
            "schema": {
              "user": {
                "fields": {
                  "role": {
                    "type": "string",
                    "required": false,
                    "input": false
                  },
                  "banned": {
                    "type": "boolean",
                    "defaultValue": false,
                    "required": false,
                    "input": false
                  },
                  "banReason": {
                    "type": "string",
                    "required": false,
                    "input": false
                  },
                  "banExpires": {
                    "type": "date",
                    "required": false,
                    "input": false
                  }
                }
              },
              "session": {
                "fields": {
                  "impersonatedBy": {
                    "type": "string",
                    "required": false
                  }
                }
              }
            },
            "options": {
              "ac": {
                "statements": {
                  "user": [
                    "create",
                    "list",
                    "set-role",
                    "ban",
                    "impersonate",
                    "delete",
                    "set-password",
                    "get",
                    "update"
                  ],
                  "session": [
                    "list",
                    "revoke",
                    "delete"
                  ],
                  "project": [
                    "create",
                    "read",
                    "update",
                    "delete"
                  ]
                }
              },
              "roles": {
                "admin": {
                  "statements": {
                    "user": [
                      "create",
                      "list",
                      "set-role",
                      "ban",
                      "impersonate",
                      "delete",
                      "set-password",
                      "get",
                      "update"
                    ],
                    "session": [
                      "list",
                      "revoke",
                      "delete"
                    ],
                    "project": [
                      "create",
                      "read",
                      "update",
                      "delete"
                    ]
                  }
                },
                "talent": {
                  "statements": {
                    "project": [
                      "create",
                      "read",
                      "update",
                      "delete"
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "name": "organization",
          "config": {
            "id": "organization",
            "endpoints": {},
            "schema": {
              "organization": {
                "fields": {
                  "name": {
                    "type": "string",
                    "required": true,
                    "sortable": true
                  },
                  "slug": {
                    "type": "string",
                    "required": true,
                    "unique": true,
                    "sortable": true
                  },
                  "logo": {
                    "type": "string",
                    "required": false
                  },
                  "createdAt": {
                    "type": "date",
                    "required": true
                  },
                  "metadata": {
                    "type": "string",
                    "required": false
                  },
                  "shop": {
                    "type": "string",
                    "input": true,
                    "required": true
                  }
                }
              },
              "organizationRole": {
                "fields": {
                  "organizationId": {
                    "type": "string",
                    "required": true,
                    "references": {
                      "model": "organization",
                      "field": "id"
                    },
                    "index": true
                  },
                  "role": {
                    "type": "string",
                    "required": true,
                    "index": true
                  },
                  "permission": {
                    "type": "string",
                    "required": true
                  },
                  "createdAt": {
                    "type": "date",
                    "required": true
                  },
                  "updatedAt": {
                    "type": "date",
                    "required": false
                  }
                }
              },
              "member": {
                "fields": {
                  "organizationId": {
                    "type": "string",
                    "required": true,
                    "references": {
                      "model": "organization",
                      "field": "id"
                    },
                    "index": true
                  },
                  "userId": {
                    "type": "string",
                    "required": true,
                    "references": {
                      "model": "user",
                      "field": "id"
                    },
                    "index": true
                  },
                  "role": {
                    "type": "string",
                    "required": true,
                    "sortable": true,
                    "defaultValue": "member"
                  },
                  "createdAt": {
                    "type": "date",
                    "required": true
                  }
                }
              },
              "invitation": {
                "fields": {
                  "organizationId": {
                    "type": "string",
                    "required": true,
                    "references": {
                      "model": "organization",
                      "field": "id"
                    },
                    "index": true
                  },
                  "email": {
                    "type": "string",
                    "required": true,
                    "sortable": true,
                    "index": true
                  },
                  "role": {
                    "type": "string",
                    "required": false,
                    "sortable": true
                  },
                  "status": {
                    "type": "string",
                    "required": true,
                    "sortable": true,
                    "defaultValue": "pending"
                  },
                  "expiresAt": {
                    "type": "date",
                    "required": true
                  },
                  "createdAt": {
                    "type": "date",
                    "required": true
                  },
                  "inviterId": {
                    "type": "string",
                    "references": {
                      "model": "user",
                      "field": "id"
                    },
                    "required": true
                  }
                }
              },
              "session": {
                "fields": {
                  "activeOrganizationId": {
                    "type": "string",
                    "required": false
                  }
                }
              }
            },
            "$Infer": {
              "Organization": {},
              "Invitation": {},
              "Member": {},
              "Team": {},
              "TeamMember": {},
              "ActiveOrganization": {}
            },
            "$ERROR_CODES": {
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION": "You are not allowed to create a new organization",
              "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS": "You have reached the maximum number of organizations",
              "ORGANIZATION_ALREADY_EXISTS": "Organization already exists",
              "ORGANIZATION_SLUG_ALREADY_TAKEN": "Organization slug already taken",
              "ORGANIZATION_NOT_FOUND": "Organization not found",
              "USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION": "User is not a member of the organization",
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_ORGANIZATION": "You are not allowed to update this organization",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_ORGANIZATION": "You are not allowed to delete this organization",
              "NO_ACTIVE_ORGANIZATION": "No active organization",
              "USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION": "User is already a member of this organization",
              "MEMBER_NOT_FOUND": "Member not found",
              "ROLE_NOT_FOUND": "Role not found",
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM": "You are not allowed to create a new team",
              "TEAM_ALREADY_EXISTS": "Team already exists",
              "TEAM_NOT_FOUND": "Team not found",
              "YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER": "You cannot leave the organization as the only owner",
              "YOU_CANNOT_LEAVE_THE_ORGANIZATION_WITHOUT_AN_OWNER": "You cannot leave the organization without an owner",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_MEMBER": "You are not allowed to delete this member",
              "YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION": "You are not allowed to invite users to this organization",
              "USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION": "User is already invited to this organization",
              "INVITATION_NOT_FOUND": "Invitation not found",
              "YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION": "You are not the recipient of the invitation",
              "EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION": "Email verification required before accepting or rejecting invitation",
              "YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION": "You are not allowed to cancel this invitation",
              "INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION": "Inviter is no longer a member of the organization",
              "YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE": "You are not allowed to invite a user with this role",
              "FAILED_TO_RETRIEVE_INVITATION": "Failed to retrieve invitation",
              "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS": "You have reached the maximum number of teams",
              "UNABLE_TO_REMOVE_LAST_TEAM": "Unable to remove last team",
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_MEMBER": "You are not allowed to update this member",
              "ORGANIZATION_MEMBERSHIP_LIMIT_REACHED": "Organization membership limit reached",
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION": "You are not allowed to create teams in this organization",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION": "You are not allowed to delete teams in this organization",
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM": "You are not allowed to update this team",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM": "You are not allowed to delete this team",
              "INVITATION_LIMIT_REACHED": "Invitation limit reached",
              "TEAM_MEMBER_LIMIT_REACHED": "Team member limit reached",
              "USER_IS_NOT_A_MEMBER_OF_THE_TEAM": "User is not a member of the team",
              "YOU_CAN_NOT_ACCESS_THE_MEMBERS_OF_THIS_TEAM": "You are not allowed to list the members of this team",
              "YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM": "You do not have an active team",
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER": "You are not allowed to create a new member",
              "YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER": "You are not allowed to remove a team member",
              "YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION": "You are not allowed to access this organization as an owner",
              "YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION": "You are not a member of this organization",
              "MISSING_AC_INSTANCE": "Dynamic Access Control requires a pre-defined ac instance on the server auth plugin. Read server logs for more information",
              "YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE": "You must be in an organization to create a role",
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE": "You are not allowed to create a role",
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE": "You are not allowed to update a role",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE": "You are not allowed to delete a role",
              "YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE": "You are not allowed to read a role",
              "YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE": "You are not allowed to list a role",
              "YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE": "You are not allowed to get a role",
              "TOO_MANY_ROLES": "This organization has too many roles",
              "INVALID_RESOURCE": "The provided permission includes an invalid resource",
              "ROLE_NAME_IS_ALREADY_TAKEN": "That role name is already taken",
              "CANNOT_DELETE_A_PRE_DEFINED_ROLE": "Cannot delete a pre-defined role"
            },
            "options": {
              "ac": {
                "statements": {
                  "user": [
                    "create",
                    "list",
                    "set-role",
                    "ban",
                    "impersonate",
                    "delete",
                    "set-password",
                    "get",
                    "update"
                  ],
                  "session": [
                    "list",
                    "revoke",
                    "delete"
                  ],
                  "project": [
                    "create",
                    "read",
                    "update",
                    "delete"
                  ]
                }
              },
              "dynamicAccessControl": {
                "enabled": true
              },
              "allowUserToCreateOrganization": true,
              "schema": {
                "organization": {
                  "additionalFields": {
                    "shop": {
                      "type": "string",
                      "input": true,
                      "required": true
                    }
                  }
                }
              }
            }
          }
        },
        {
          "name": "bearer",
          "config": {
            "id": "bearer",
            "hooks": {
              "before": [
                {}
              ],
              "after": [
                {}
              ]
            }
          }
        }
      ]
    }
  }
}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

For additional context, this is a custom plugin I made for Shopify.

I tried doing the Prisma way:

await db.create({
    model: 'member',
    data: {
      organization: { connect: { id: organization.id } },
      userId: user.id,
      role: 'owner',
      createdAt: new Date(),
    },
})

The organization part is fine. It just when I try to create a member is having issues. Not really sure what I'm missing here.

Originally created by @m0L3cuL3 on GitHub (Dec 15, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```typescript const db = ctx.context.adapter; // Try to find org by slug (shop name) let organization: any = await db.findOne({ model: 'organization', where: [{ field: 'slug', value: shopName }], }); if (!organization) { // Create New Organization organization = await db.create({ model: 'organization', data: { name: shopName, slug: shopName, userId: user.id, // Owner createdAt: new Date(), metadata: JSON.stringify({ shopifyAccessToken: accessToken, shopifyApiKey: apiKey, }), shop: shopDomain, }, }); // Add Owner Member await db.create({ model: 'member', data: { organizationId: organization.id, userId: user.id, role: 'owner', createdAt: new Date(), }, }); } else { if (accessToken) { await db.update({ model: 'organization', where: [{ field: 'id', value: organization.id }], update: { metadata: JSON.stringify({ shopifyAccessToken: accessToken, shopifyApiKey: apiKey, }), }, }); } const member = await db.findOne({ model: 'member', where: [ { field: 'organizationId', value: organization.id }, { field: 'userId', value: user.id }, ], }); if (!member) { await db.create({ model: 'member', data: { organizationId: organization.id, userId: user.id, role: 'member', createdAt: new Date(), }, }); } } ``` ### Current vs. Expected behavior **Current Behavior:** - It throws the `PrismaClientValidationError` ```shell Invalid `prisma.member.create()` invocation: { data: { role: "member", createdAt: new Date("2025-12-15T08:12:52.541Z"), id: "9CvR23r2bkGI4oa4VswPWcMelSVzPz8b", + organization: { + create: OrganizationCreateWithoutMembersInput | OrganizationUncheckedCreateWithoutMembersInput, + connectOrCreate: OrganizationCreateOrConnectWithoutMembersInput, + connect: OrganizationWhereUniqueInput + } }, select: undefined } Argument `organization` is missing. ``` **Expected Behavior:** - It should create a member ### What version of Better Auth are you using? 1.4.6 ### System info ```bash "system": { "platform": "win32", "arch": "x64", "version": "Windows 10 Pro", "release": "10.0.19045", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5600G with Radeon Graphics ", "totalMemory": "23.37 GB", "freeMemory": "4.16 GB" }, "node": { "version": "v20.19.5", "env": "production" }, "packageManager": { "name": "npm", "version": "10.8.2" }, "frameworks": [ { "name": "express", "version": "^4.21.2" } ], "databases": [ { "name": "@prisma/client", "version": "^6.12.0" } ], "betterAuth": { "version": "^1.4.6", "config": { "user": { "additionalFields": { "bio": { "type": "string", "required": false, "input": true } } }, "emailAndPassword": { "enabled": true }, "plugins": [ { "name": "open-api", "config": { "id": "open-api", "endpoints": {} } }, { "name": "passkey", "config": { "id": "passkey", "endpoints": {}, "schema": { "passkey": { "fields": { "name": { "type": "string", "required": false }, "publicKey": { "type": "string", "required": true }, "userId": { "type": "string", "references": { "model": "user", "field": "id" }, "required": true, "index": true }, "credentialID": { "type": "string", "required": true, "index": true }, "counter": { "type": "number", "required": true }, "deviceType": { "type": "string", "required": true }, "backedUp": { "type": "boolean", "required": true }, "transports": { "type": "string", "required": false }, "createdAt": { "type": "date", "required": false }, "aaguid": { "type": "string", "required": false } } } }, "$ERROR_CODES": { "CHALLENGE_NOT_FOUND": "Challenge not found", "YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY": "You are not allowed to register this passkey", "FAILED_TO_VERIFY_REGISTRATION": "Failed to verify registration", "PASSKEY_NOT_FOUND": "Passkey not found", "AUTHENTICATION_FAILED": "Authentication failed", "UNABLE_TO_CREATE_SESSION": "Unable to create session", "FAILED_TO_UPDATE_PASSKEY": "Failed to update passkey" } } }, { "name": "shopify-auth", "config": { "id": "shopify-auth", "endpoints": {} } }, { "name": "custom-session", "config": { "id": "custom-session", "hooks": { "after": [ {} ] }, "endpoints": {}, "$Infer": { "Session": {} } } }, { "name": "admin", "config": { "id": "admin", "hooks": { "after": [ {} ] }, "endpoints": {}, "$ERROR_CODES": { "FAILED_TO_CREATE_USER": "Failed to create user", "USER_ALREADY_EXISTS": "User already exists.", "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL": "User already exists. Use another email.", "YOU_CANNOT_BAN_YOURSELF": "You cannot ban yourself", "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE": "You are not allowed to change users role", "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS": "You are not allowed to create users", "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS": "You are not allowed to list users", "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS": "You are not allowed to list users sessions", "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS": "You are not allowed to ban users", "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS": "You are not allowed to impersonate users", "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS": "You are not allowed to revoke users sessions", "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS": "You are not allowed to delete users", "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD": "[REDACTED]", "BANNED_USER": "You have been banned from this application", "YOU_ARE_NOT_ALLOWED_TO_GET_USER": "You are not allowed to get user", "NO_DATA_TO_UPDATE": "No data to update", "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS": "You are not allowed to update users", "YOU_CANNOT_REMOVE_YOURSELF": "You cannot remove yourself", "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE": "You are not allowed to set a non-existent role value", "YOU_CANNOT_IMPERSONATE_ADMINS": "You cannot impersonate admins" }, "schema": { "user": { "fields": { "role": { "type": "string", "required": false, "input": false }, "banned": { "type": "boolean", "defaultValue": false, "required": false, "input": false }, "banReason": { "type": "string", "required": false, "input": false }, "banExpires": { "type": "date", "required": false, "input": false } } }, "session": { "fields": { "impersonatedBy": { "type": "string", "required": false } } } }, "options": { "ac": { "statements": { "user": [ "create", "list", "set-role", "ban", "impersonate", "delete", "set-password", "get", "update" ], "session": [ "list", "revoke", "delete" ], "project": [ "create", "read", "update", "delete" ] } }, "roles": { "admin": { "statements": { "user": [ "create", "list", "set-role", "ban", "impersonate", "delete", "set-password", "get", "update" ], "session": [ "list", "revoke", "delete" ], "project": [ "create", "read", "update", "delete" ] } }, "talent": { "statements": { "project": [ "create", "read", "update", "delete" ] } } } } } }, { "name": "organization", "config": { "id": "organization", "endpoints": {}, "schema": { "organization": { "fields": { "name": { "type": "string", "required": true, "sortable": true }, "slug": { "type": "string", "required": true, "unique": true, "sortable": true }, "logo": { "type": "string", "required": false }, "createdAt": { "type": "date", "required": true }, "metadata": { "type": "string", "required": false }, "shop": { "type": "string", "input": true, "required": true } } }, "organizationRole": { "fields": { "organizationId": { "type": "string", "required": true, "references": { "model": "organization", "field": "id" }, "index": true }, "role": { "type": "string", "required": true, "index": true }, "permission": { "type": "string", "required": true }, "createdAt": { "type": "date", "required": true }, "updatedAt": { "type": "date", "required": false } } }, "member": { "fields": { "organizationId": { "type": "string", "required": true, "references": { "model": "organization", "field": "id" }, "index": true }, "userId": { "type": "string", "required": true, "references": { "model": "user", "field": "id" }, "index": true }, "role": { "type": "string", "required": true, "sortable": true, "defaultValue": "member" }, "createdAt": { "type": "date", "required": true } } }, "invitation": { "fields": { "organizationId": { "type": "string", "required": true, "references": { "model": "organization", "field": "id" }, "index": true }, "email": { "type": "string", "required": true, "sortable": true, "index": true }, "role": { "type": "string", "required": false, "sortable": true }, "status": { "type": "string", "required": true, "sortable": true, "defaultValue": "pending" }, "expiresAt": { "type": "date", "required": true }, "createdAt": { "type": "date", "required": true }, "inviterId": { "type": "string", "references": { "model": "user", "field": "id" }, "required": true } } }, "session": { "fields": { "activeOrganizationId": { "type": "string", "required": false } } } }, "$Infer": { "Organization": {}, "Invitation": {}, "Member": {}, "Team": {}, "TeamMember": {}, "ActiveOrganization": {} }, "$ERROR_CODES": { "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION": "You are not allowed to create a new organization", "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS": "You have reached the maximum number of organizations", "ORGANIZATION_ALREADY_EXISTS": "Organization already exists", "ORGANIZATION_SLUG_ALREADY_TAKEN": "Organization slug already taken", "ORGANIZATION_NOT_FOUND": "Organization not found", "USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION": "User is not a member of the organization", "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_ORGANIZATION": "You are not allowed to update this organization", "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_ORGANIZATION": "You are not allowed to delete this organization", "NO_ACTIVE_ORGANIZATION": "No active organization", "USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION": "User is already a member of this organization", "MEMBER_NOT_FOUND": "Member not found", "ROLE_NOT_FOUND": "Role not found", "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM": "You are not allowed to create a new team", "TEAM_ALREADY_EXISTS": "Team already exists", "TEAM_NOT_FOUND": "Team not found", "YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER": "You cannot leave the organization as the only owner", "YOU_CANNOT_LEAVE_THE_ORGANIZATION_WITHOUT_AN_OWNER": "You cannot leave the organization without an owner", "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_MEMBER": "You are not allowed to delete this member", "YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION": "You are not allowed to invite users to this organization", "USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION": "User is already invited to this organization", "INVITATION_NOT_FOUND": "Invitation not found", "YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION": "You are not the recipient of the invitation", "EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION": "Email verification required before accepting or rejecting invitation", "YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION": "You are not allowed to cancel this invitation", "INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION": "Inviter is no longer a member of the organization", "YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE": "You are not allowed to invite a user with this role", "FAILED_TO_RETRIEVE_INVITATION": "Failed to retrieve invitation", "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS": "You have reached the maximum number of teams", "UNABLE_TO_REMOVE_LAST_TEAM": "Unable to remove last team", "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_MEMBER": "You are not allowed to update this member", "ORGANIZATION_MEMBERSHIP_LIMIT_REACHED": "Organization membership limit reached", "YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION": "You are not allowed to create teams in this organization", "YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION": "You are not allowed to delete teams in this organization", "YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM": "You are not allowed to update this team", "YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM": "You are not allowed to delete this team", "INVITATION_LIMIT_REACHED": "Invitation limit reached", "TEAM_MEMBER_LIMIT_REACHED": "Team member limit reached", "USER_IS_NOT_A_MEMBER_OF_THE_TEAM": "User is not a member of the team", "YOU_CAN_NOT_ACCESS_THE_MEMBERS_OF_THIS_TEAM": "You are not allowed to list the members of this team", "YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM": "You do not have an active team", "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER": "You are not allowed to create a new member", "YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER": "You are not allowed to remove a team member", "YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION": "You are not allowed to access this organization as an owner", "YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION": "You are not a member of this organization", "MISSING_AC_INSTANCE": "Dynamic Access Control requires a pre-defined ac instance on the server auth plugin. Read server logs for more information", "YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE": "You must be in an organization to create a role", "YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE": "You are not allowed to create a role", "YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE": "You are not allowed to update a role", "YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE": "You are not allowed to delete a role", "YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE": "You are not allowed to read a role", "YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE": "You are not allowed to list a role", "YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE": "You are not allowed to get a role", "TOO_MANY_ROLES": "This organization has too many roles", "INVALID_RESOURCE": "The provided permission includes an invalid resource", "ROLE_NAME_IS_ALREADY_TAKEN": "That role name is already taken", "CANNOT_DELETE_A_PRE_DEFINED_ROLE": "Cannot delete a pre-defined role" }, "options": { "ac": { "statements": { "user": [ "create", "list", "set-role", "ban", "impersonate", "delete", "set-password", "get", "update" ], "session": [ "list", "revoke", "delete" ], "project": [ "create", "read", "update", "delete" ] } }, "dynamicAccessControl": { "enabled": true }, "allowUserToCreateOrganization": true, "schema": { "organization": { "additionalFields": { "shop": { "type": "string", "input": true, "required": true } } } } } } }, { "name": "bearer", "config": { "id": "bearer", "hooks": { "before": [ {} ], "after": [ {} ] } } } ] } } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context For additional context, this is a custom plugin I made for Shopify. I tried doing the Prisma way: ```typescript await db.create({ model: 'member', data: { organization: { connect: { id: organization.id } }, userId: user.id, role: 'owner', createdAt: new Date(), }, }) ``` The organization part is fine. It just when I try to create a member is having issues. Not really sure what I'm missing here.
GiteaMirror added the expressbug labels 2026-03-13 10:01:13 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 15, 2025):

tag @better-auth-agent if you would like an answer from the Agent

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 (Dec 15, 2025): tag @better-auth-agent if you would like an answer from the Agent _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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 15, 2025):

The PrismaClientValidationError happens because the Better Auth Prisma adapter expects the data you pass to db.create({ model: 'member', ... }) to match your generated Prisma schema exactly—it doesn't transform or add nested relation objects like organization for you. If your Prisma schema for Member requires a nested organization relation (not just organizationId), then providing only organizationId will trigger this error. This can happen if your schema looks like:

model Member {
  id             String       @id
  organizationId String
  organization   Organization @relation(fields: [organizationId], references: [id])
  userId         String
  user           User         @relation(fields: [userId], references: [id])
  role           String
  createdAt      DateTime
}

In this case, Prisma expects either organizationId or a nested organization: { connect: { id: ... } }—but the Better Auth adapter only forwards the fields you provide, so if you pass both, it may not work as expected and can cause the error you see adapter code.

The recommended way to add a member in the organization plugin is to use the server-side API method:

await auth.api.addMember({
  body: {
    userId: user.id,
    role: 'owner',
    organizationId: organization.id,
    // teamId: ... (optional)
  }
});

This abstracts away the relation handling and avoids direct Prisma invocation issues reference.

If you need to add members from the client or expose this via HTTP, create your own backend endpoint that calls auth.api.addMember internally.

If you want to keep using db.create directly, double-check your generated Prisma schema for Member. If it requires a nested organization relation, you must provide organization: { connect: { id: ... } } instead of organizationId. But with Better Auth, using the API method is the safest and most future-proof approach.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 15, 2025): <!-- Answer --> The PrismaClientValidationError happens because the Better Auth Prisma adapter expects the data you pass to db.create({ model: 'member', ... }) to match your generated Prisma schema exactly—it doesn't transform or add nested relation objects like organization for you. If your Prisma schema for Member requires a nested organization relation (not just organizationId), then providing only organizationId will trigger this error. This can happen if your schema looks like: ```prisma model Member { id String @id organizationId String organization Organization @relation(fields: [organizationId], references: [id]) userId String user User @relation(fields: [userId], references: [id]) role String createdAt DateTime } ``` In this case, Prisma expects either organizationId or a nested organization: { connect: { id: ... } }—but the Better Auth adapter only forwards the fields you provide, so if you pass both, it may not work as expected and can cause the error you see [adapter code](https://github.com/better-auth/better-auth/blob/ff84f35aebf9f8e4b904db7e500e17c52d5605a1/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts#L245-L256). The recommended way to add a member in the organization plugin is to use the server-side API method: ```ts await auth.api.addMember({ body: { userId: user.id, role: 'owner', organizationId: organization.id, // teamId: ... (optional) } }); ``` This abstracts away the relation handling and avoids direct Prisma invocation issues [reference](https://github.com/better-auth/better-auth/issues/6334). If you need to add members from the client or expose this via HTTP, create your own backend endpoint that calls auth.api.addMember internally. If you want to keep using db.create directly, double-check your generated Prisma schema for Member. If it requires a nested organization relation, you must provide organization: { connect: { id: ... } } instead of organizationId. But with Better Auth, using the API method is the safest and most future-proof approach. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/bfd74049-aaed-4a9b-a14a-a8691b9ee793?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20PrismaClientValidationError%20happens%20because%20the%20Better%20Auth%20Prisma%20adapter%20expects%20the%20data%20you%20pass%20to%20db.create%28%7B%20model%3A%20%27member%27%2C%20...%20%7D%29%20to%20match%20your%20generated%20Prisma%20schema%20exactly%E2%80%94it%20doesn%27t%20transform%20or%20add%20nested%20relation%20objects%20like%20organization%20for%20you.%20If%20your%20Prisma%20schema%20for%20Member%20requires%20a%20nested%20organization%20relation%20%28not%20just%20organizationId%29%2C%20then%20providing%20only%20organizationId%20will%20trigger%20this%20error.%20This%20can%20happen%20if%20your%20schema%20looks%20like%3A%0A%0A%60%60%60prisma%0Amodel%20Member%20%7B%0A%20%20id%20%20%20%20%20%20%20%20%20%20%20%20%20String%20%20%20%20%20%20%20%40id%0A%20%20organizationId%20String%0A%20%20organization%20%20%20Organization%20%40relation%28fields%3A%20%5BorganizationId%5D%2C%20references%3A%20%5Bid%5D%29%0A%20%20userId%20%20%20%20%20%20%20%20%20String%0A%20%20user%20%20%20%20%20%20%20%20%20%20%20User%20%20%20%20%20%20%20%20%20%40relation%28fields%3A%20%5BuserId%5D%2C%20references%3A%20%5Bid%5D%29%0A%20%20role%20%20%20%20%20%20%20%20%20%20%20String%0A%20%20createdAt%20%20%20%20%20%20DateTime%0A%7D%0A%60%60%60%0A%0AIn%20this%20case%2C%20Prisma%20expects%20either%20organizationId%20or%20a%20nested%20organization%3A%20%7B%20connect%3A%20%7B%20id%3A%20...%20%7D%20%7D%E2%80%94but%20the%20Better%20Auth%20adapter%20only%20forwards%20the%20fields%20you%20provide%2C%20so%20if%20you%20pass%20both%2C%20it%20may%20not%20work%20as%20expected%20and%20can%20cause%20the%20error%20you%20see%C2%A0%5Badapter%20code%5D%28https%3A//github.com/better-auth/better-auth/blob/ff84f35aebf9f8e4b904db7e500e17c52d5605a1/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts%23L245-L256%29.%0A%0AThe%20recommended%20way%20to%20add%20a%20member%20in%20the%20organization%20plugin%20is%20to%20use%20the%20server-side%20API%20method%3A%20%0A%0A%60%60%60ts%0Aawait%20auth.api.addMember%28%7B%0A%20%20body%3A%20%7B%0A%20%20%20%20userId%3A%20user.id%2C%0A%20%20%20%20role%3A%20%27owner%27%2C%0A%20%20%20%20organizationId%3A%20organization.id%2C%0A%20%20%20%20//%20teamId%3A%20...%20%28optional%29%0A%20%20%7D%0A%7D%29%3B%0A%60%60%60%0A%0AThis%20abstracts%20away%20the%20relation%20handling%20and%20avoids%20direct%20Prisma%20invocation%20issues%C2%A0%5Breference%5D%28https%3A//github.com/better-auth/better-auth/issues/6334%29.%0A%0AIf%20you%20need%20to%20add%20members%20from%20the%20client%20or%20expose%20this%20via%20HTTP%2C%20create%20your%20own%20backend%20endpoint%20that%20calls%20auth.api.addMember%20internally.%0A%0AIf%20you%20want%20to%20keep%20using%20db.create%20directly%2C%20double-check%20your%20generated%20Prisma%20schema%20for%20Member.%20If%20it%20requires%20a%20nested%20organization%20relation%2C%20you%20must%20provide%20organization%3A%20%7B%20connect%3A%20%7B%20id%3A%20...%20%7D%20%7D%20instead%20of%20organizationId.%20But%20with%20Better%20Auth%2C%20using%20the%20API%20method%20is%20the%20safest%20and%20most%20future-proof%20approach.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6768)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2533