| 310 | // inviteCode }`); Better Auth reads the body loosely, so a non-schema field |
| 311 | // survives to the create hook's endpoint context. |
| 312 | const inviteCodeFrom = (context: { body?: unknown }): string | undefined => { |
| 313 | const body = context.body; |
| 314 | if (body && typeof body === "object" && "inviteCode" in body) { |
| 315 | const code = (body as { inviteCode?: unknown }).inviteCode; |
| 316 | if (typeof code === "string" && code.trim().length > 0) return code; |
| 317 | } |
| 318 | return undefined; |
| 319 | }; |
| 320 | |
| 321 | // Count org members via Better Auth's OWN adapter. Now that auth shares |
| 322 | // SelfHostDb's libSQL client (one connection), this no longer guards against a |