| 231 | // inviteCode }`); Better Auth reads the body loosely, so a non-schema field |
| 232 | // survives to the create hook's endpoint context. |
| 233 | const inviteCodeFrom = (context: { body?: unknown }): string | undefined => { |
| 234 | const body = context.body; |
| 235 | if (body && typeof body === "object" && "inviteCode" in body) { |
| 236 | const code = (body as { inviteCode?: unknown }).inviteCode; |
| 237 | if (typeof code === "string" && code.trim().length > 0) return code; |
| 238 | } |
| 239 | return undefined; |
| 240 | }; |
| 241 | |
| 242 | // Count org members via Better Auth's OWN adapter. Now that auth shares |
| 243 | // SelfHostDb's libSQL client (one connection), this no longer guards against a |