You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(better-auth): extract architecture docs to separate file
Move "Architecture: Why Custom Controllers?" section from README.md
to dedicated ARCHITECTURE.md file for better documentation structure.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The `CoreBetterAuthController` implements custom endpoints instead of directly using native Better-Auth endpoints. This is **necessary** for the nest-server hybrid auth system.
4
+
5
+
## 1. Hybrid-Auth-System (Legacy + Better-Auth)
6
+
7
+
The nest-server supports bidirectional authentication:
8
+
-**Legacy Auth → Better-Auth**: Users created via Legacy Auth can sign in via Better-Auth
9
+
-**Better-Auth → Legacy Auth**: Users created via Better-Auth can sign in via Legacy Auth
10
+
11
+
This requires custom logic that cannot be implemented via Better-Auth hooks alone.
12
+
13
+
## 2. Why Not Better-Auth Hooks?
14
+
15
+
Better-Auth hooks have fundamental limitations that prevent full implementation of our requirements:
16
+
17
+
| Requirement | Hook Support | Reason |
18
+
|-------------|--------------|--------|
19
+
| Legacy user migration | ⚠️ Partial | Requires global DB access outside NestJS DI |
20
+
| Password sync to Legacy | ❌ No |**After-hooks don't have access to plaintext password**|
21
+
| Custom response format | ❌ No |**Hooks cannot modify HTTP response**|
22
+
| Multi-cookie setting | ❌ No |**Hooks cannot set cookies**|
23
+
| User mapping with roles | ❌ No | Requires NestJS Dependency Injection |
24
+
| Session token injection | ❌ No | Before-hooks cannot inject tokens into requests |
Copy file name to clipboardExpand all lines: src/core/modules/better-auth/INTEGRATION-CHECKLIST.md
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -439,6 +439,84 @@ async function deletePasskey(passkeyId: string) {
439
439
440
440
---
441
441
442
+
## Better-Auth Hooks: Limitations & Warnings
443
+
444
+
### Why nest-server Uses Custom Controllers
445
+
446
+
nest-server implements custom REST endpoints instead of relying solely on Better-Auth hooks. This is **by design** due to fundamental hook limitations.
447
+
448
+
### Hook Limitations Summary
449
+
450
+
| Limitation | Impact |
451
+
|------------|--------|
452
+
| **After-hooks cannot access plaintext password** | Cannot sync password to Legacy Auth after sign-up |
453
+
| **Hooks cannot modify HTTP response** | Cannot customize response format or add custom fields |
0 commit comments