diff --git a/.claude/rules/better-auth.md b/.claude/rules/better-auth.md index 1011f58..4832093 100644 --- a/.claude/rules/better-auth.md +++ b/.claude/rules/better-auth.md @@ -117,6 +117,140 @@ When changes affect existing test expectations: 3. **Update test** to match new correct behavior 4. **Document** why the test was changed in commit message +## 4. Customization Patterns + +When a project needs custom BetterAuth behavior, follow these patterns: + +### Module Registration Patterns + +| Pattern | Use When | Configuration | +|---------|----------|---------------| +| **Zero-Config** | No customization needed | `CoreModule.forRoot(envConfig)` | +| **Config-based** | Custom Controller/Resolver | `betterAuth: { controller, resolver }` in config | +| **Separate Module** | Full control, additional providers | `betterAuth: { autoRegister: false }` | + +### Pattern Selection Decision Tree + +1. Does the project need custom Controller or Resolver? + - No → Use Zero-Config (Pattern 1) + - Yes → Continue to 2 + +2. Does the project need additional providers or complex module structure? + - No → Use Config-based (Pattern 2) - add `controller`/`resolver` to `betterAuth` config + - Yes → Use Separate Module (Pattern 3) - set `autoRegister: false` + +### Critical: Resolver Decorator Re-declaration + +When customizing the Resolver, **ALL decorators MUST be re-declared**: + +```typescript +// WRONG - method won't appear in GraphQL schema! +override async betterAuthSignUp(...) { + return super.betterAuthSignUp(...); +} + +// CORRECT - all decorators re-declared +@Mutation(() => BetterAuthAuthModel) +@Roles(RoleEnum.S_EVERYONE) +override async betterAuthSignUp(...) { + return super.betterAuthSignUp(...); +} +``` + +**Why:** GraphQL schema is built from decorators at compile time. Parent class is `isAbstract: true`. + +### Email Template Customization + +Templates are resolved in order: +1. `