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