@lobehub/lobehub 2.0.0-next.124 → 2.0.0-next.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/.cursor/rules/db-migrations.mdc +16 -1
  2. package/.cursor/rules/project-introduce.mdc +1 -1
  3. package/.cursor/rules/project-structure.mdc +20 -2
  4. package/.env.example +148 -65
  5. package/.env.example.development +6 -8
  6. package/AGENTS.md +1 -3
  7. package/CHANGELOG.md +25 -0
  8. package/Dockerfile +6 -6
  9. package/GEMINI.md +63 -0
  10. package/changelog/v1.json +9 -0
  11. package/docs/development/database-schema.dbml +37 -0
  12. package/docs/self-hosting/advanced/auth.mdx +75 -2
  13. package/docs/self-hosting/advanced/auth.zh-CN.mdx +75 -2
  14. package/docs/self-hosting/environment-variables/auth.mdx +187 -1
  15. package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +187 -1
  16. package/locales/en-US/auth.json +93 -0
  17. package/locales/zh-CN/auth.json +107 -1
  18. package/package.json +5 -2
  19. package/packages/const/src/auth.ts +2 -1
  20. package/packages/database/migrations/0049_better_auth.sql +49 -0
  21. package/packages/database/migrations/meta/0048_snapshot.json +312 -932
  22. package/packages/database/migrations/meta/0049_snapshot.json +8151 -0
  23. package/packages/database/migrations/meta/_journal.json +8 -1
  24. package/packages/database/src/core/migrations.json +13 -0
  25. package/packages/database/src/index.ts +1 -0
  26. package/packages/database/src/models/__tests__/session.test.ts +1 -2
  27. package/packages/database/src/models/user.ts +9 -8
  28. package/packages/database/src/repositories/tableViewer/index.test.ts +2 -2
  29. package/packages/database/src/schemas/betterAuth.ts +63 -0
  30. package/packages/database/src/schemas/index.ts +1 -0
  31. package/packages/database/src/schemas/ragEvals.ts +1 -2
  32. package/packages/database/src/schemas/user.ts +3 -2
  33. package/packages/database/src/server/models/__tests__/user.test.ts +1 -4
  34. package/packages/types/src/user/preference.ts +11 -0
  35. package/packages/utils/src/server/__tests__/auth.test.ts +52 -0
  36. package/packages/utils/src/server/auth.ts +18 -1
  37. package/src/app/(backend)/api/auth/[...all]/route.ts +19 -0
  38. package/src/app/(backend)/api/auth/check-user/route.ts +62 -0
  39. package/src/app/(backend)/middleware/auth/index.ts +14 -0
  40. package/src/app/(backend)/middleware/auth/utils.test.ts +16 -0
  41. package/src/app/(backend)/middleware/auth/utils.ts +13 -10
  42. package/src/app/(backend)/webapi/chat/[provider]/route.test.ts +1 -0
  43. package/src/app/[variants]/(auth)/reset-password/layout.tsx +12 -0
  44. package/src/app/[variants]/(auth)/reset-password/page.tsx +209 -0
  45. package/src/app/[variants]/(auth)/signin/layout.tsx +12 -0
  46. package/src/app/[variants]/(auth)/signin/page.tsx +448 -0
  47. package/src/app/[variants]/(auth)/signup/[[...signup]]/BetterAuthSignUpForm.tsx +192 -0
  48. package/src/app/[variants]/(auth)/signup/[[...signup]]/page.tsx +31 -6
  49. package/src/app/[variants]/(auth)/verify-email/layout.tsx +12 -0
  50. package/src/app/[variants]/(auth)/verify-email/page.tsx +164 -0
  51. package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/UserBanner.test.tsx +12 -10
  52. package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +13 -11
  53. package/src/app/[variants]/(main)/profile/(home)/Client.tsx +306 -52
  54. package/src/app/[variants]/(main)/profile/(home)/features/SSOProvidersList/index.tsx +89 -47
  55. package/src/auth.ts +118 -0
  56. package/src/components/NextAuth/AuthIcons.tsx +3 -1
  57. package/src/envs/auth.ts +260 -13
  58. package/src/envs/email.ts +37 -0
  59. package/src/features/User/UserPanel/PanelContent.tsx +6 -5
  60. package/src/features/User/__tests__/PanelContent.test.tsx +15 -6
  61. package/src/features/User/__tests__/UserAvatar.test.tsx +17 -6
  62. package/src/features/User/__tests__/useMenu.test.tsx +14 -12
  63. package/src/layout/AuthProvider/BetterAuth/UserUpdater.tsx +51 -0
  64. package/src/layout/AuthProvider/BetterAuth/index.tsx +14 -0
  65. package/src/layout/AuthProvider/index.tsx +3 -0
  66. package/src/libs/better-auth/auth-client.ts +34 -0
  67. package/src/libs/better-auth/constants.ts +13 -0
  68. package/src/libs/better-auth/email-templates/index.ts +3 -0
  69. package/src/libs/better-auth/email-templates/magic-link.ts +98 -0
  70. package/src/libs/better-auth/email-templates/reset-password.ts +91 -0
  71. package/src/libs/better-auth/email-templates/verification.ts +108 -0
  72. package/src/libs/better-auth/sso/helpers.ts +61 -0
  73. package/src/libs/better-auth/sso/index.ts +113 -0
  74. package/src/libs/better-auth/sso/providers/auth0.ts +33 -0
  75. package/src/libs/better-auth/sso/providers/authelia.ts +35 -0
  76. package/src/libs/better-auth/sso/providers/authentik.ts +35 -0
  77. package/src/libs/better-auth/sso/providers/casdoor.ts +48 -0
  78. package/src/libs/better-auth/sso/providers/cloudflare-zero-trust.ts +41 -0
  79. package/src/libs/better-auth/sso/providers/cognito.ts +45 -0
  80. package/src/libs/better-auth/sso/providers/feishu.ts +181 -0
  81. package/src/libs/better-auth/sso/providers/generic-oidc.ts +44 -0
  82. package/src/libs/better-auth/sso/providers/github.ts +30 -0
  83. package/src/libs/better-auth/sso/providers/google.ts +30 -0
  84. package/src/libs/better-auth/sso/providers/keycloak.ts +35 -0
  85. package/src/libs/better-auth/sso/providers/logto.ts +38 -0
  86. package/src/libs/better-auth/sso/providers/microsoft.ts +65 -0
  87. package/src/libs/better-auth/sso/providers/okta.ts +37 -0
  88. package/src/libs/better-auth/sso/providers/wechat.ts +140 -0
  89. package/src/libs/better-auth/sso/providers/zitadel.ts +54 -0
  90. package/src/libs/better-auth/sso/types.ts +25 -0
  91. package/src/libs/better-auth/utils/client.ts +1 -0
  92. package/src/libs/better-auth/utils/common.ts +20 -0
  93. package/src/libs/better-auth/utils/server.test.ts +61 -0
  94. package/src/libs/better-auth/utils/server.ts +18 -0
  95. package/src/libs/trpc/lambda/context.test.ts +116 -0
  96. package/src/libs/trpc/lambda/context.ts +27 -0
  97. package/src/libs/trpc/middleware/userAuth.ts +4 -2
  98. package/src/locales/default/auth.ts +114 -1
  99. package/src/proxy.ts +71 -7
  100. package/src/server/globalConfig/index.ts +12 -1
  101. package/src/server/routers/lambda/user.ts +4 -0
  102. package/src/server/services/email/README.md +241 -0
  103. package/src/server/services/email/impls/index.test.ts +39 -0
  104. package/src/server/services/email/impls/index.ts +32 -0
  105. package/src/server/services/email/impls/nodemailer/index.ts +108 -0
  106. package/src/server/services/email/impls/nodemailer/type.ts +31 -0
  107. package/src/server/services/email/impls/type.ts +61 -0
  108. package/src/server/services/email/index.test.ts +144 -0
  109. package/src/server/services/email/index.ts +40 -0
  110. package/src/services/user/index.test.ts +162 -2
  111. package/src/services/user/index.ts +6 -3
  112. package/src/store/user/slices/auth/action.test.ts +213 -16
  113. package/src/store/user/slices/auth/action.ts +86 -1
  114. package/src/store/user/slices/auth/initialState.ts +13 -2
  115. package/src/store/user/slices/auth/selectors.ts +6 -2
  116. package/src/store/user/slices/common/action.ts +5 -1
  117. package/src/app/(backend)/api/auth/[...nextauth]/route.ts +0 -3
@@ -5,7 +5,22 @@ alwaysApply: false
5
5
 
6
6
  # Database Migrations Guide
7
7
 
8
- ## Defensive Programming - Use Idempotent Clauses
8
+ ## Step1: Generate migrations:
9
+
10
+ ```bash
11
+ bun run db:generate
12
+ ```
13
+
14
+ this step will generate or update the following files:
15
+
16
+ - packages/database/migrations/0046_xxx.sql
17
+ - packages/database/migrations/meta/\_journal.json
18
+
19
+ ## Step2: optimize the migration sql fileName
20
+
21
+ the migration sql file name is randomly generated, we need to optimize the file name to make it more readable and meaningful. For example, `0046_xxx.sql` -> `0046_better_auth.sql`
22
+
23
+ ## Step3: Defensive Programming - Use Idempotent Clauses
9
24
 
10
25
  Always use defensive clauses to make migrations idempotent:
11
26
 
@@ -16,7 +16,7 @@ logo emoji: 🤯
16
16
 
17
17
  ## Project Technologies Stack
18
18
 
19
- - Next.js 15
19
+ - Next.js 16
20
20
  - react 19
21
21
  - TypeScript
22
22
  - `@lobehub/ui`, antd for component framework
@@ -16,17 +16,28 @@ lobe-chat/
16
16
  ├── apps/
17
17
  │ └── desktop/
18
18
  ├── docs/
19
+ │ ├── changelog/
20
+ │ ├── development/
21
+ │ ├── self-hosting/
22
+ │ └── usage/
19
23
  ├── locales/
20
24
  │ ├── en-US/
21
25
  │ └── zh-CN/
22
26
  ├── packages/
27
+ │ ├── agent-runtime/
23
28
  │ ├── const/
24
29
  │ ├── context-engine/
30
+ │ ├── conversation-flow/
25
31
  │ ├── database/
26
32
  │ │ ├── src/
27
33
  │ │ │ ├── models/
28
34
  │ │ │ ├── schemas/
29
35
  │ │ │ └── repositories/
36
+ │ ├── electron-client-ipc/
37
+ │ ├── electron-server-ipc/
38
+ │ ├── fetch-sse/
39
+ │ ├── file-loaders/
40
+ │ ├── memory-extract/
30
41
  │ ├── model-bank/
31
42
  │ │ └── src/
32
43
  │ │ └── aiModels/
@@ -34,11 +45,16 @@ lobe-chat/
34
45
  │ │ └── src/
35
46
  │ │ ├── core/
36
47
  │ │ └── providers/
48
+ │ ├── obervability-otel/
49
+ │ ├── prompts/
50
+ │ ├── python-interpreter/
51
+ │ ├── ssrf-safe-fetch/
37
52
  │ ├── types/
38
53
  │ │ └── src/
39
54
  │ │ ├── message/
40
55
  │ │ └── user/
41
- └── utils/
56
+ ├── utils/
57
+ │ └── web-crawler/
42
58
  ├── public/
43
59
  ├── scripts/
44
60
  ├── src/
@@ -68,7 +84,9 @@ lobe-chat/
68
84
  │ │ ├── AuthProvider/
69
85
  │ │ └── GlobalProvider/
70
86
  │ ├── libs/
71
- │ │ └── oidc-provider/
87
+ │ │ ├── better-auth/
88
+ │ │ ├── oidc-provider/
89
+ │ │ └── trpc/
72
90
  │ ├── locales/
73
91
  │ │ └── default/
74
92
  │ ├── server/
package/.env.example CHANGED
@@ -4,9 +4,9 @@
4
4
  # Specify your API Key selection method, currently supporting `random` and `turn`.
5
5
  # API_KEY_SELECT_MODE=random
6
6
 
7
- ########################################
8
- ########### Security Settings ###########
9
- ########################################
7
+ # #######################################
8
+ # ########## Security Settings ###########
9
+ # #######################################
10
10
 
11
11
  # Control Content Security Policy headers
12
12
  # Set to '1' to enable X-Frame-Options and Content-Security-Policy headers
@@ -24,11 +24,11 @@
24
24
  # Example: Allow specific internal servers while keeping SSRF protection
25
25
  # SSRF_ALLOW_IP_ADDRESS_LIST=192.168.1.100,10.0.0.50
26
26
 
27
- ########################################
28
- ########## AI Provider Service #########
29
- ########################################
27
+ # #######################################
28
+ # ######### AI Provider Service #########
29
+ # #######################################
30
30
 
31
- ### OpenAI ###
31
+ # ## OpenAI ###
32
32
 
33
33
  # you openai api key
34
34
  OPENAI_API_KEY=sk-xxxxxxxxx
@@ -40,7 +40,7 @@ OPENAI_API_KEY=sk-xxxxxxxxx
40
40
  # OPENAI_MODEL_LIST=gpt-3.5-turbo
41
41
 
42
42
 
43
- ### Azure OpenAI ###
43
+ # ## Azure OpenAI ###
44
44
 
45
45
  # you can learn azure OpenAI Service on https://learn.microsoft.com/en-us/azure/ai-services/openai/overview
46
46
  # use Azure OpenAI Service by uncomment the following line
@@ -55,7 +55,7 @@ OPENAI_API_KEY=sk-xxxxxxxxx
55
55
  # AZURE_API_VERSION=2024-10-21
56
56
 
57
57
 
58
- ### Anthropic Service ####
58
+ # ## Anthropic Service ####
59
59
 
60
60
  # ANTHROPIC_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
61
61
 
@@ -63,19 +63,19 @@ OPENAI_API_KEY=sk-xxxxxxxxx
63
63
  # ANTHROPIC_PROXY_URL=https://api.anthropic.com
64
64
 
65
65
 
66
- ### Google AI ####
66
+ # ## Google AI ####
67
67
 
68
68
  # GOOGLE_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
69
69
 
70
70
 
71
- ### AWS Bedrock ###
71
+ # ## AWS Bedrock ###
72
72
 
73
73
  # AWS_REGION=us-east-1
74
74
  # AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxx
75
75
  # AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
76
76
 
77
77
 
78
- ### Ollama AI ####
78
+ # ## Ollama AI ####
79
79
 
80
80
  # You can use ollama to get and run LLM locally, learn more about it via https://github.com/ollama/ollama
81
81
 
@@ -85,132 +85,132 @@ OPENAI_API_KEY=sk-xxxxxxxxx
85
85
  # OLLAMA_MODEL_LIST=your_ollama_model_names
86
86
 
87
87
 
88
- ### OpenRouter Service ###
88
+ # ## OpenRouter Service ###
89
89
 
90
90
  # OPENROUTER_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
91
91
  # OPENROUTER_MODEL_LIST=model1,model2,model3
92
92
 
93
93
 
94
- ### Mistral AI ###
94
+ # ## Mistral AI ###
95
95
 
96
96
  # MISTRAL_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
97
97
 
98
- ### Perplexity Service ###
98
+ # ## Perplexity Service ###
99
99
 
100
100
  # PERPLEXITY_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
101
101
 
102
- ### Groq Service ####
102
+ # ## Groq Service ####
103
103
 
104
104
  # GROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
105
105
 
106
- #### 01.AI Service ####
106
+ # ### 01.AI Service ####
107
107
 
108
108
  # ZEROONE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
109
109
 
110
- ### TogetherAI Service ###
110
+ # ## TogetherAI Service ###
111
111
 
112
112
  # TOGETHERAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
113
113
 
114
- ### ZhiPu AI ###
114
+ # ## ZhiPu AI ###
115
115
 
116
116
  # ZHIPU_API_KEY=xxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxx
117
117
 
118
- ### Moonshot AI ####
118
+ # ## Moonshot AI ####
119
119
 
120
120
  # MOONSHOT_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
121
121
 
122
- ### Minimax AI ####
122
+ # ## Minimax AI ####
123
123
 
124
124
  # MINIMAX_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
125
125
 
126
- ### DeepSeek AI ####
126
+ # ## DeepSeek AI ####
127
127
 
128
128
  # DEEPSEEK_PROXY_URL=https://api.deepseek.com/v1
129
129
  # DEEPSEEK_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
130
130
 
131
- ### Qiniu AI ####
131
+ # ## Qiniu AI ####
132
132
 
133
133
  # QINIU_PROXY_URL=https://api.qnaigc.com/v1
134
134
  # QINIU_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
135
135
 
136
- ### Qwen AI ####
136
+ # ## Qwen AI ####
137
137
 
138
138
  # QWEN_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
139
139
 
140
- ### Cloudflare Workers AI ####
140
+ # ## Cloudflare Workers AI ####
141
141
 
142
142
  # CLOUDFLARE_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
143
143
  # CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
144
144
 
145
- ### SiliconCloud AI ####
145
+ # ## SiliconCloud AI ####
146
146
 
147
147
  # SILICONCLOUD_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
148
148
 
149
149
 
150
- ### TencentCloud AI ####
150
+ # ## TencentCloud AI ####
151
151
 
152
152
  # TENCENT_CLOUD_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
153
153
 
154
- ### PPIO ####
154
+ # ## PPIO ####
155
155
 
156
156
  # PPIO_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
157
157
 
158
- ### INFINI-AI ###
158
+ # ## INFINI-AI ###
159
159
 
160
160
  # INFINIAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
161
161
 
162
162
 
163
- ### 302.AI ###
163
+ # ## 302.AI ###
164
164
 
165
165
  # AI302_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
166
166
 
167
- ### ModelScope ###
167
+ # ## ModelScope ###
168
168
 
169
169
  # MODELSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
170
170
 
171
- ### AiHubMix ###
171
+ # ## AiHubMix ###
172
172
 
173
173
  # AIHUBMIX_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
174
174
 
175
- ### BFL ###
175
+ # ## BFL ###
176
176
 
177
177
  # BFL_API_KEY=bfl-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
178
178
 
179
- ### FAL ###
179
+ # ## FAL ###
180
180
 
181
181
  # FAL_API_KEY=fal-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
182
182
 
183
- ########################################
184
- ######### AI Image Settings ############
185
- ########################################
183
+ # #######################################
184
+ # ######## AI Image Settings ############
185
+ # #######################################
186
186
 
187
187
  # Default image generation count (range: 1-20, default: 4)
188
188
  # AI_IMAGE_DEFAULT_IMAGE_NUM=4
189
189
 
190
- ### Nebius ###
190
+ # ## Nebius ###
191
191
 
192
192
  # NEBIUS_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
193
193
 
194
- ### NewAPI Service ###
194
+ # ## NewAPI Service ###
195
195
 
196
196
  # NEWAPI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
197
197
  # NEWAPI_PROXY_URL=https://your-newapi-server.com
198
198
 
199
- ### Vercel AI Gateway ###
199
+ # ## Vercel AI Gateway ###
200
200
 
201
201
  # VERCELAIGATEWAY_API_KEY=your_vercel_ai_gateway_api_key
202
202
 
203
203
 
204
- ########################################
205
- ############ Market Service ############
206
- ########################################
204
+ # #######################################
205
+ # ########### Market Service ############
206
+ # #######################################
207
207
 
208
208
  # The LobeChat agents market index url
209
209
  # AGENTS_INDEX_URL=https://chat-agents.lobehub.com
210
210
 
211
- ########################################
212
- ############ Plugin Service ############
213
- ########################################
211
+ # #######################################
212
+ # ########### Plugin Service ############
213
+ # #######################################
214
214
 
215
215
  # The LobeChat plugins store index url
216
216
  # PLUGINS_INDEX_URL=https://chat-plugins.lobehub.com
@@ -219,9 +219,9 @@ OPENAI_API_KEY=sk-xxxxxxxxx
219
219
  # the format is `plugin-identifier:key1=value1;key2=value2`, multiple settings fields are separated by semicolons `;`, multiple plugin settings are separated by commas `,`.
220
220
  # PLUGIN_SETTINGS=search-engine:SERPAPI_API_KEY=xxxxx
221
221
 
222
- ########################################
223
- ####### Doc / Changelog Service ########
224
- ########################################
222
+ # #######################################
223
+ # ###### Doc / Changelog Service ########
224
+ # #######################################
225
225
 
226
226
  # Use in Changelog / Document service cdn url prefix
227
227
  # DOC_S3_PUBLIC_DOMAIN=https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -231,9 +231,9 @@ OPENAI_API_KEY=sk-xxxxxxxxx
231
231
  # DOC_S3_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
232
232
 
233
233
 
234
- ########################################
235
- ##### S3 Object Storage Service ########
236
- ########################################
234
+ # #######################################
235
+ # #### S3 Object Storage Service ########
236
+ # #######################################
237
237
 
238
238
  # S3 keys
239
239
  # S3_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -253,19 +253,19 @@ OPENAI_API_KEY=sk-xxxxxxxxx
253
253
  # S3_REGION=us-west-1
254
254
 
255
255
 
256
- ########################################
257
- ############ Auth Service ##############
258
- ########################################
256
+ # #######################################
257
+ # ########### Auth Service ##############
258
+ # #######################################
259
259
 
260
260
 
261
261
  # Clerk related configurations
262
262
 
263
263
  # Clerk public key and secret key
264
- #NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxx
265
- #CLERK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxx
264
+ # NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxx
265
+ # CLERK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxx
266
266
 
267
267
  # you need to config the clerk webhook secret key if you want to use the clerk with database
268
- #CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx
268
+ # CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx
269
269
 
270
270
  # Clear allow origin https://clerk.com/docs/guides/dashboard/dns-domains/satellite-domains
271
271
  # Authentication across different domains , use,to splite different origin
@@ -280,23 +280,106 @@ OPENAI_API_KEY=sk-xxxxxxxxx
280
280
  # AUTH_AUTH0_SECRET=
281
281
  # AUTH_AUTH0_ISSUER=https://your-domain.auth0.com
282
282
 
283
- ########################################
284
- ########## Server Database #############
285
- ########################################
283
+ # Better-Auth related configurations
284
+ # NEXT_PUBLIC_ENABLE_BETTER_AUTH=1
285
+
286
+ # Auth Secret (use `openssl rand -base64 32` to generate)
287
+ # Shared between Better-Auth and Next-Auth
288
+ # AUTH_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
289
+
290
+ # Auth URL (accessible from browser, optional if same domain)
291
+ # NEXT_PUBLIC_AUTH_URL=http://localhost:3210
292
+
293
+ # Require email verification before allowing users to sign in (default: false)
294
+ # Set to '1' to force users to verify their email before signing in
295
+ # NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION=0
296
+
297
+ # SSO Providers Configuration (for Better-Auth)
298
+ # Comma-separated list of enabled OAuth providers
299
+ # Supported providers: auth0, authelia, authentik, casdoor, cloudflare-zero-trust, cognito, generic-oidc, github, google, keycloak, logto, microsoft, microsoft-entra-id, okta, zitadel
300
+ # Example: AUTH_SSO_PROVIDERS=google,github,auth0,microsoft-entra-id
301
+ # AUTH_SSO_PROVIDERS=
302
+
303
+ # Google OAuth Configuration (for Better-Auth)
304
+ # Get credentials from: https://console.cloud.google.com/apis/credentials
305
+ # Authorized redirect URIs:
306
+ # - Development: http://localhost:3210/api/auth/callback/google
307
+ # - Production: https://yourdomain.com/api/auth/callback/google
308
+ # GOOGLE_CLIENT_ID=xxxxx.apps.googleusercontent.com
309
+ # GOOGLE_CLIENT_SECRET=GOCSPX-xxxxxxxxxxxxxxxxxxxx
310
+
311
+ # GitHub OAuth Configuration (for Better-Auth)
312
+ # Get credentials from: https://github.com/settings/developers
313
+ # Create a new OAuth App with:
314
+ # Authorized callback URL:
315
+ # - Development: http://localhost:3210/api/auth/callback/github
316
+ # - Production: https://yourdomain.com/api/auth/callback/github
317
+ # GITHUB_CLIENT_ID=Ov23xxxxxxxxxxxxx
318
+ # GITHUB_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
319
+
320
+ # AWS Cognito OAuth Configuration (for Better-Auth)
321
+ # Get credentials from: https://console.aws.amazon.com/cognito
322
+ # Setup steps:
323
+ # 1. Create a User Pool with App Client
324
+ # 2. Configure Hosted UI domain
325
+ # 3. Enable "Authorization code grant" OAuth flow
326
+ # 4. Set OAuth scopes: openid, profile, email
327
+ # Authorized callback URL:
328
+ # - Development: http://localhost:3210/api/auth/callback/cognito
329
+ # - Production: https://yourdomain.com/api/auth/callback/cognito
330
+ # COGNITO_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxx
331
+ # COGNITO_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
332
+ # COGNITO_DOMAIN=your-app.auth.us-east-1.amazoncognito.com
333
+ # COGNITO_REGION=us-east-1
334
+ # COGNITO_USERPOOL_ID=us-east-1_xxxxxxxxx
335
+
336
+ # Microsoft OAuth Configuration (for Better-Auth)
337
+ # Get credentials from: https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade
338
+ # Create a new App Registration in Microsoft Entra ID (Azure AD)
339
+ # Authorized redirect URL:
340
+ # - Development: http://localhost:3210/api/auth/callback/microsoft
341
+ # - Production: https://yourdomain.com/api/auth/callback/microsoft
342
+ # MICROSOFT_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
343
+ # MICROSOFT_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
344
+
345
+ # #######################################
346
+ # ########## Email Service ##############
347
+ # #######################################
348
+
349
+ # SMTP Server Configuration (required for email verification with Better-Auth)
350
+
351
+ # SMTP server hostname (e.g., smtp.gmail.com, smtp.office365.com)
352
+ # SMTP_HOST=smtp.example.com
353
+
354
+ # SMTP server port (usually 587 for TLS, or 465 for SSL)
355
+ # SMTP_PORT=587
356
+
357
+ # Use secure connection (set to 'true' for port 465, 'false' for port 587)
358
+ # SMTP_SECURE=false
359
+
360
+ # SMTP authentication username (usually your email address)
361
+ # SMTP_USER=your-email@example.com
362
+
363
+ # SMTP authentication password (use app-specific password for Gmail)
364
+ # SMTP_PASS=your-password-or-app-specific-password
365
+
366
+ # #######################################
367
+ # ######### Server Database #############
368
+ # #######################################
286
369
 
287
370
  # Postgres database URL
288
371
  # DATABASE_URL=postgres://username:password@host:port/database
289
372
 
290
373
  # use `openssl rand -base64 32` to generate a key for the encryption of the database
291
374
  # we use this key to encrypt the user api key and proxy url
292
- #KEY_VAULTS_SECRET=xxxxx/xxxxxxxxxxxxxx=
375
+ # KEY_VAULTS_SECRET=xxxxx/xxxxxxxxxxxxxx=
293
376
 
294
377
  # Specify the Embedding model and Reranker model(unImplemented)
295
378
  # DEFAULT_FILES_CONFIG="embedding_model=openai/embedding-text-3-small,reranker_model=cohere/rerank-english-v3.0,query_mode=full_text"
296
379
 
297
- ########################################
298
- ########## MCP Service Config ##########
299
- ########################################
380
+ # #######################################
381
+ # ######### MCP Service Config ##########
382
+ # #######################################
300
383
 
301
384
  # MCP tool call timeout (milliseconds)
302
385
  # MCP_TOOL_TIMEOUT=60000
@@ -32,19 +32,17 @@ DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@localhost:5432/${LOBE_DB
32
32
  DATABASE_DRIVER=node
33
33
 
34
34
  # Authentication Configuration
35
- # Enable NextAuth authentication
36
- NEXT_PUBLIC_ENABLE_NEXT_AUTH=1
35
+ # Enable Better Auth authentication
36
+ NEXT_PUBLIC_ENABLE_BETTER_AUTH=1
37
37
 
38
- # NextAuth secret for JWT signing (generate with: openssl rand -base64 32)
39
- NEXT_AUTH_SECRET=${UNSAFE_SECRET}
40
-
41
- NEXTAUTH_URL=${APP_URL}
38
+ # Better Auth secret for JWT signing (generate with: openssl rand -base64 32)
39
+ AUTH_SECRET=${UNSAFE_SECRET}
42
40
 
43
41
  # Authentication URL
44
- AUTH_URL=${APP_URL}/api/auth
42
+ NEXT_PUBLIC_AUTH_URL=${APP_URL}
45
43
 
46
44
  # SSO providers configuration - using Casdoor for development
47
- NEXT_AUTH_SSO_PROVIDERS=casdoor
45
+ AUTH_SSO_PROVIDERS=casdoor
48
46
 
49
47
  # Casdoor Configuration
50
48
  # Casdoor service port
package/AGENTS.md CHANGED
@@ -6,13 +6,12 @@ This document serves as a comprehensive guide for all team members when developi
6
6
 
7
7
  Built with modern technologies:
8
8
 
9
- - **Frontend**: Next.js 15, React 19, TypeScript
9
+ - **Frontend**: Next.js 16, React 19, TypeScript
10
10
  - **UI Components**: Ant Design, @lobehub/ui, antd-style
11
11
  - **State Management**: Zustand, SWR
12
12
  - **Database**: PostgreSQL, PGLite, Drizzle ORM
13
13
  - **Testing**: Vitest, Testing Library
14
14
  - **Package Manager**: pnpm (monorepo structure)
15
- - **Build Tools**: Next.js (Turbopack in dev, Webpack in prod)
16
15
 
17
16
  ## Directory Structure
18
17
 
@@ -39,7 +38,6 @@ The project follows a well-organized monorepo structure:
39
38
  - Use `pnpm` as the primary package manager
40
39
  - Use `bun` to run npm scripts
41
40
  - Use `bunx` to run executable npm packages
42
- - Navigate to specific packages using `cd packages/<package-name>`
43
41
 
44
42
  ### Code Style Guidelines
45
43
 
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 2.0.0-next.125](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.124...v2.0.0-next.125)
6
+
7
+ <sup>Released on **2025-11-27**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support better-auth.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support better-auth, closes [#10215](https://github.com/lobehub/lobe-chat/issues/10215) ([dc62cc9](https://github.com/lobehub/lobe-chat/commit/dc62cc9))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ## [Version 2.0.0-next.124](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.123...v2.0.0-next.124)
6
31
 
7
32
  <sup>Released on **2025-11-27**</sup>
package/Dockerfile CHANGED
@@ -37,7 +37,7 @@ FROM base AS builder
37
37
 
38
38
  ARG USE_CN_MIRROR
39
39
  ARG NEXT_PUBLIC_BASE_PATH
40
- ARG NEXT_PUBLIC_ENABLE_NEXT_AUTH
40
+ ARG NEXT_PUBLIC_ENABLE_BETTER_AUTH
41
41
  ARG NEXT_PUBLIC_ENABLE_CLERK_AUTH
42
42
  ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
43
43
  ARG NEXT_PUBLIC_SENTRY_DSN
@@ -52,7 +52,7 @@ ARG FEATURE_FLAGS
52
52
  ENV NEXT_PUBLIC_BASE_PATH="${NEXT_PUBLIC_BASE_PATH}" \
53
53
  FEATURE_FLAGS="${FEATURE_FLAGS}"
54
54
 
55
- ENV NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
55
+ ENV NEXT_PUBLIC_ENABLE_BETTER_AUTH="${NEXT_PUBLIC_ENABLE_BETTER_AUTH:-1}" \
56
56
  NEXT_PUBLIC_ENABLE_CLERK_AUTH="${NEXT_PUBLIC_ENABLE_CLERK_AUTH:-0}" \
57
57
  NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}" \
58
58
  CLERK_WEBHOOK_SECRET="whsec_xxx" \
@@ -177,10 +177,10 @@ ENV KEY_VAULTS_SECRET="" \
177
177
  DATABASE_DRIVER="node" \
178
178
  DATABASE_URL=""
179
179
 
180
- # Next Auth
181
- ENV NEXT_AUTH_SECRET="" \
182
- NEXT_AUTH_SSO_PROVIDERS="" \
183
- NEXTAUTH_URL=""
180
+ # Better Auth
181
+ ENV AUTH_SECRET="" \
182
+ AUTH_SSO_PROVIDERS="" \
183
+ NEXT_PUBLIC_AUTH_URL=""
184
184
 
185
185
  # Clerk
186
186
  ENV CLERK_SECRET_KEY="" \
package/GEMINI.md ADDED
@@ -0,0 +1,63 @@
1
+ # GEMINI.md
2
+
3
+ This document serves as a shared guideline for all team members when using Gemini CLI in this repository.
4
+
5
+ ## Tech Stack
6
+
7
+ read @.cursor/rules/project-introduce.mdc
8
+
9
+ ## Directory Structure
10
+
11
+ read @.cursor/rules/project-structure.mdc
12
+
13
+ ## Development
14
+
15
+ ### Git Workflow
16
+
17
+ - use rebase for git pull
18
+ - git commit message should prefix with gitmoji
19
+ - git branch name format example: tj/feat/feature-name
20
+ - use .github/PULL_REQUEST_TEMPLATE.md to generate pull request description
21
+
22
+ ### Package Management
23
+
24
+ This repository adopts a monorepo structure.
25
+
26
+ - Use `pnpm` as the primary package manager for dependency management
27
+ - Use `bun` to run npm scripts
28
+ - Use `bunx` to run executable npm packages
29
+
30
+ ### TypeScript Code Style Guide
31
+
32
+ see @.cursor/rules/typescript.mdc
33
+
34
+ ### Testing
35
+
36
+ - **Required Rule**: read `@.cursor/rules/testing-guide/testing-guide.mdc` before writing tests
37
+ - **Command**:
38
+ - web: `bunx vitest run --silent='passed-only' '[file-path-pattern]'`
39
+ - packages(eg: database): `cd packages/database && bunx vitest run --silent='passed-only' '[file-path-pattern]'`
40
+
41
+ **Important**:
42
+
43
+ - wrap the file path in single quotes to avoid shell expansion
44
+ - Never run `bun run test` etc to run tests, this will run all tests and cost about 10mins
45
+ - If trying to fix the same test twice, but still failed, stop and ask for help.
46
+
47
+ ### Typecheck
48
+
49
+ - use `bun run type-check` to check type errors.
50
+
51
+ ### i18n
52
+
53
+ - **Keys**: Add to `src/locales/default/namespace.ts`
54
+ - **Dev**: Translate `locales/zh-CN/namespace.json` and `locales/en-US/namespace.json` locales file only for dev preview
55
+ - DON'T run `pnpm i18n`, let CI auto handle it
56
+
57
+ ## 🚨 Quality Checks
58
+
59
+ **MANDATORY**: After completing code changes, always run `mcp__vscode-mcp__get_diagnostics` on the modified files to identify any errors introduced by your changes and fix them.
60
+
61
+ ## Rules Index
62
+
63
+ Some useful project rules are listed in @.cursor/rules/rules-index.mdc
package/changelog/v1.json CHANGED
@@ -1,4 +1,13 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "features": [
5
+ "Support better-auth."
6
+ ]
7
+ },
8
+ "date": "2025-11-27",
9
+ "version": "2.0.0-next.125"
10
+ },
2
11
  {
3
12
  "children": {
4
13
  "fixes": [