| 212 | // inviteCode }`); Better Auth reads the body loosely, so a non-schema field |
| 213 | // survives to the create hook's endpoint context. |
| 214 | const inviteCodeFrom = (context: { body?: unknown }): string | undefined => { |
| 215 | const body = context.body; |
| 216 | if (body && typeof body === "object" && "inviteCode" in body) { |
| 217 | const code = (body as { inviteCode?: unknown }).inviteCode; |
| 218 | if (typeof code === "string" && code.trim().length > 0) return code; |
| 219 | } |
| 220 | return undefined; |
| 221 | }; |
| 222 | |
| 223 | // Count org members via Better Auth's OWN adapter. Now that auth shares |
| 224 | // SelfHostDb's libSQL client (one connection), this no longer guards against a |