@lobehub/lobehub 2.0.0-next.354 → 2.0.0-next.356

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 (176) hide show
  1. package/.env.desktop +0 -1
  2. package/.env.example +16 -20
  3. package/.env.example.development +1 -4
  4. package/.github/workflows/e2e.yml +10 -11
  5. package/CHANGELOG.md +60 -0
  6. package/Dockerfile +28 -4
  7. package/changelog/v1.json +18 -0
  8. package/docker-compose/local/docker-compose.yml +2 -2
  9. package/docker-compose/local/grafana/docker-compose.yml +2 -2
  10. package/docker-compose/local/logto/docker-compose.yml +2 -2
  11. package/docker-compose/local/zitadel/.env.example +2 -2
  12. package/docker-compose/local/zitadel/.env.zh-CN.example +2 -2
  13. package/docker-compose/production/grafana/docker-compose.yml +2 -2
  14. package/docker-compose/production/logto/.env.example +2 -2
  15. package/docker-compose/production/logto/.env.zh-CN.example +2 -2
  16. package/docker-compose/production/zitadel/.env.example +2 -2
  17. package/docker-compose/production/zitadel/.env.zh-CN.example +2 -2
  18. package/docs/development/basic/add-new-authentication-providers.mdx +144 -136
  19. package/docs/development/basic/add-new-authentication-providers.zh-CN.mdx +146 -136
  20. package/docs/self-hosting/advanced/auth/legacy.mdx +4 -0
  21. package/docs/self-hosting/advanced/auth/legacy.zh-CN.mdx +4 -0
  22. package/docs/self-hosting/advanced/auth/nextauth-to-betterauth.mdx +326 -0
  23. package/docs/self-hosting/advanced/auth/nextauth-to-betterauth.zh-CN.mdx +323 -0
  24. package/docs/self-hosting/advanced/auth.mdx +43 -16
  25. package/docs/self-hosting/advanced/auth.zh-CN.mdx +44 -16
  26. package/docs/self-hosting/advanced/redis/upstash.mdx +69 -0
  27. package/docs/self-hosting/advanced/redis/upstash.zh-CN.mdx +69 -0
  28. package/docs/self-hosting/advanced/redis.mdx +128 -0
  29. package/docs/self-hosting/advanced/redis.zh-CN.mdx +126 -0
  30. package/docs/self-hosting/environment-variables/auth.mdx +15 -1
  31. package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +15 -1
  32. package/docs/self-hosting/environment-variables/basic.mdx +13 -0
  33. package/docs/self-hosting/environment-variables/basic.zh-CN.mdx +13 -0
  34. package/docs/self-hosting/environment-variables/redis.mdx +68 -0
  35. package/docs/self-hosting/environment-variables/redis.zh-CN.mdx +67 -0
  36. package/docs/self-hosting/migration/v2/breaking-changes.mdx +23 -23
  37. package/docs/self-hosting/migration/v2/breaking-changes.zh-CN.mdx +23 -23
  38. package/docs/self-hosting/server-database/docker-compose.mdx +4 -4
  39. package/docs/self-hosting/server-database/docker-compose.zh-CN.mdx +4 -4
  40. package/e2e/CLAUDE.md +5 -6
  41. package/e2e/docs/local-setup.md +9 -12
  42. package/e2e/scripts/setup.ts +9 -15
  43. package/e2e/src/support/webServer.ts +6 -5
  44. package/locales/en-US/plugin.json +3 -0
  45. package/locales/zh-CN/plugin.json +3 -0
  46. package/package.json +4 -6
  47. package/packages/builtin-tool-memory/src/client/Render/SearchUserMemory/index.tsx +3 -11
  48. package/packages/context-engine/src/engine/messages/MessagesEngine.ts +0 -13
  49. package/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts +0 -25
  50. package/packages/database/src/models/__tests__/topics/topic.create.test.ts +3 -3
  51. package/packages/database/src/schemas/nextauth.ts +7 -2
  52. package/packages/utils/src/server/__tests__/auth.test.ts +1 -63
  53. package/packages/utils/src/server/auth.ts +8 -24
  54. package/scripts/_shared/checkDeprecatedAuth.js +99 -0
  55. package/scripts/clerk-to-betterauth/index.ts +8 -3
  56. package/scripts/nextauth-to-betterauth/_internal/config.ts +41 -0
  57. package/scripts/nextauth-to-betterauth/_internal/db.ts +32 -0
  58. package/scripts/nextauth-to-betterauth/_internal/env.ts +6 -0
  59. package/scripts/nextauth-to-betterauth/index.ts +226 -0
  60. package/scripts/nextauth-to-betterauth/verify.ts +188 -0
  61. package/scripts/prebuild.mts +66 -13
  62. package/scripts/serverLauncher/startServer.js +5 -5
  63. package/src/app/(backend)/api/auth/[...all]/route.ts +5 -23
  64. package/src/app/(backend)/api/webhooks/casdoor/route.ts +5 -5
  65. package/src/app/(backend)/api/webhooks/logto/route.ts +8 -8
  66. package/src/app/(backend)/middleware/auth/index.test.ts +8 -1
  67. package/src/app/(backend)/middleware/auth/index.ts +6 -15
  68. package/src/app/(backend)/middleware/auth/utils.test.ts +0 -32
  69. package/src/app/(backend)/middleware/auth/utils.ts +3 -8
  70. package/src/app/(backend)/webapi/chat/[provider]/route.test.ts +8 -1
  71. package/src/app/(backend)/webapi/create-image/comfyui/route.ts +0 -1
  72. package/src/app/(backend)/webapi/models/[provider]/route.test.ts +8 -1
  73. package/src/app/[variants]/(auth)/signin/SignInEmailStep.tsx +1 -1
  74. package/src/app/[variants]/(auth)/signup/[[...signup]]/page.tsx +4 -17
  75. package/src/app/[variants]/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx +1 -0
  76. package/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobContentEditor.tsx +34 -21
  77. package/src/app/[variants]/(main)/agent/features/Conversation/ConversationArea.tsx +4 -0
  78. package/src/app/[variants]/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx +1 -0
  79. package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentItem/index.tsx +1 -1
  80. package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/InboxItem.tsx +19 -29
  81. package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/List.tsx +1 -1
  82. package/src/app/[variants]/(main)/home/_layout/Body/Agent/ModalProvider.tsx +1 -1
  83. package/src/app/[variants]/(main)/settings/profile/features/SSOProvidersList/index.tsx +12 -19
  84. package/src/app/[variants]/(main)/settings/profile/index.tsx +8 -14
  85. package/src/components/{NextAuth/AuthIcons.tsx → AuthIcons.tsx} +8 -10
  86. package/src/envs/auth.ts +12 -51
  87. package/src/envs/email.ts +3 -0
  88. package/src/envs/redis.ts +12 -54
  89. package/src/features/ChatInput/ChatInputProvider.tsx +22 -2
  90. package/src/features/ChatInput/InputEditor/index.tsx +14 -3
  91. package/src/features/ChatInput/store/initialState.ts +2 -0
  92. package/src/features/User/__tests__/PanelContent.test.tsx +0 -11
  93. package/src/features/User/__tests__/UserAvatar.test.tsx +1 -16
  94. package/src/layout/AuthProvider/index.tsx +1 -6
  95. package/src/layout/GlobalProvider/StoreInitialization.tsx +2 -4
  96. package/src/libs/better-auth/define-config.ts +2 -0
  97. package/src/libs/better-auth/plugins/email-whitelist.test.ts +120 -0
  98. package/src/libs/better-auth/plugins/email-whitelist.ts +62 -0
  99. package/src/libs/next/config/define-config.ts +13 -1
  100. package/src/libs/next/proxy/define-config.ts +2 -75
  101. package/src/libs/oidc-provider/provider.test.ts +0 -4
  102. package/src/libs/redis/index.ts +0 -1
  103. package/src/libs/redis/manager.test.ts +9 -45
  104. package/src/libs/redis/manager.ts +2 -16
  105. package/src/libs/redis/redis.test.ts +2 -4
  106. package/src/libs/redis/redis.ts +2 -4
  107. package/src/libs/redis/types.ts +2 -24
  108. package/src/libs/redis/utils.test.ts +0 -10
  109. package/src/libs/redis/utils.ts +0 -19
  110. package/src/libs/trpc/lambda/context.test.ts +0 -13
  111. package/src/libs/trpc/lambda/context.ts +21 -59
  112. package/src/libs/trpc/middleware/userAuth.ts +1 -7
  113. package/src/libs/trusted-client/getSessionUser.ts +15 -35
  114. package/src/locales/default/plugin.ts +3 -0
  115. package/src/server/globalConfig/index.ts +1 -3
  116. package/src/server/modules/Mecha/ContextEngineering/__tests__/serverMessagesEngine.test.ts +0 -25
  117. package/src/server/routers/lambda/__tests__/user.test.ts +0 -48
  118. package/src/server/routers/lambda/user.ts +1 -12
  119. package/src/server/services/email/impls/nodemailer/index.ts +2 -2
  120. package/src/server/services/webhookUser/index.ts +88 -0
  121. package/src/services/chat/chat.test.ts +19 -19
  122. package/src/services/chat/index.ts +8 -3
  123. package/src/services/chat/mecha/agentConfigResolver.test.ts +72 -55
  124. package/src/services/chat/mecha/agentConfigResolver.ts +28 -4
  125. package/src/services/chat/mecha/contextEngineering.test.ts +21 -14
  126. package/src/services/chat/mecha/contextEngineering.ts +12 -0
  127. package/src/services/chat/types.ts +7 -1
  128. package/src/services/user/index.test.ts +0 -14
  129. package/src/services/user/index.ts +0 -4
  130. package/src/store/chat/agents/createAgentExecutors.ts +15 -4
  131. package/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts +1 -0
  132. package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +6 -2
  133. package/src/store/user/slices/auth/action.test.ts +22 -126
  134. package/src/store/user/slices/auth/action.ts +32 -65
  135. package/src/store/user/slices/auth/initialState.ts +0 -3
  136. package/src/store/user/slices/auth/selectors.ts +0 -3
  137. package/tests/setup.ts +10 -0
  138. package/scripts/_shared/checkDeprecatedClerkEnv.js +0 -42
  139. package/src/app/(backend)/api/auth/adapter/route.ts +0 -137
  140. package/src/app/[variants]/(auth)/next-auth/error/AuthErrorPage.tsx +0 -40
  141. package/src/app/[variants]/(auth)/next-auth/error/page.tsx +0 -11
  142. package/src/app/[variants]/(auth)/next-auth/signin/AuthSignInBox.tsx +0 -167
  143. package/src/app/[variants]/(auth)/next-auth/signin/page.tsx +0 -11
  144. package/src/app/[variants]/(auth)/reset-password/layout.tsx +0 -12
  145. package/src/app/[variants]/(auth)/signin/layout.tsx +0 -12
  146. package/src/app/[variants]/(auth)/verify-email/layout.tsx +0 -12
  147. package/src/envs/auth.test.ts +0 -47
  148. package/src/layout/AuthProvider/NextAuth/UserUpdater.tsx +0 -44
  149. package/src/layout/AuthProvider/NextAuth/index.tsx +0 -17
  150. package/src/libs/next-auth/adapter/index.ts +0 -177
  151. package/src/libs/next-auth/auth.config.ts +0 -64
  152. package/src/libs/next-auth/index.ts +0 -20
  153. package/src/libs/next-auth/sso-providers/auth0.ts +0 -24
  154. package/src/libs/next-auth/sso-providers/authelia.ts +0 -39
  155. package/src/libs/next-auth/sso-providers/authentik.ts +0 -25
  156. package/src/libs/next-auth/sso-providers/casdoor.ts +0 -50
  157. package/src/libs/next-auth/sso-providers/cloudflare-zero-trust.ts +0 -34
  158. package/src/libs/next-auth/sso-providers/cognito.ts +0 -8
  159. package/src/libs/next-auth/sso-providers/feishu.ts +0 -83
  160. package/src/libs/next-auth/sso-providers/generic-oidc.ts +0 -38
  161. package/src/libs/next-auth/sso-providers/github.ts +0 -23
  162. package/src/libs/next-auth/sso-providers/google.ts +0 -18
  163. package/src/libs/next-auth/sso-providers/index.ts +0 -35
  164. package/src/libs/next-auth/sso-providers/keycloak.ts +0 -22
  165. package/src/libs/next-auth/sso-providers/logto.ts +0 -48
  166. package/src/libs/next-auth/sso-providers/microsoft-entra-id-helper.ts +0 -29
  167. package/src/libs/next-auth/sso-providers/microsoft-entra-id.ts +0 -19
  168. package/src/libs/next-auth/sso-providers/okta.ts +0 -22
  169. package/src/libs/next-auth/sso-providers/sso.config.ts +0 -8
  170. package/src/libs/next-auth/sso-providers/wechat.ts +0 -36
  171. package/src/libs/next-auth/sso-providers/zitadel.ts +0 -21
  172. package/src/libs/redis/upstash.test.ts +0 -158
  173. package/src/libs/redis/upstash.ts +0 -136
  174. package/src/server/services/nextAuthUser/index.ts +0 -318
  175. package/src/server/services/nextAuthUser/utils.ts +0 -62
  176. package/src/types/next-auth.d.ts +0 -26
@@ -110,14 +110,15 @@ Used by email verification, password reset, and magic-link delivery. Two provide
110
110
 
111
111
  Send emails via SMTP protocol, suitable for users with existing email services. See [Nodemailer SMTP docs](https://nodemailer.com/smtp/).
112
112
 
113
- | Environment Variable | Type | Description | Example |
114
- | ------------------------ | -------- | ------------------------------------------------------- | ------------------- |
115
- | `EMAIL_SERVICE_PROVIDER` | Optional | Set to `nodemailer` (default) | `nodemailer` |
116
- | `SMTP_HOST` | Required | SMTP server hostname | `smtp.gmail.com` |
117
- | `SMTP_PORT` | Required | SMTP server port (`587` for TLS, `465` for SSL) | `587` |
118
- | `SMTP_SECURE` | Optional | `true` for SSL (port 465), `false` for TLS (port 587) | `false` |
119
- | `SMTP_USER` | Required | SMTP auth username | `user@gmail.com` |
120
- | `SMTP_PASS` | Required | SMTP auth password | `your-app-password` |
113
+ | Environment Variable | Type | Description | Example |
114
+ | ------------------------ | -------- | ----------------------------------------------------------------- | ---------------------- |
115
+ | `EMAIL_SERVICE_PROVIDER` | Optional | Set to `nodemailer` (default) | `nodemailer` |
116
+ | `SMTP_HOST` | Required | SMTP server hostname | `smtp.gmail.com` |
117
+ | `SMTP_PORT` | Required | SMTP server port (`587` for TLS, `465` for SSL) | `587` |
118
+ | `SMTP_SECURE` | Optional | `true` for SSL (port 465), `false` for TLS (port 587) | `false` |
119
+ | `SMTP_USER` | Required | SMTP auth username | `user@gmail.com` |
120
+ | `SMTP_PASS` | Required | SMTP auth password | `your-app-password` |
121
+ | `SMTP_FROM` | Optional | Sender address (required for AWS SES), defaults to `SMTP_USER` | `noreply@example.com` |
121
122
 
122
123
  <Callout type={'warning'}>
123
124
  When using Gmail, you must use an App Password instead of your account password. Generate one at [Google App Passwords](https://myaccount.google.com/apppasswords).
@@ -127,11 +128,11 @@ Send emails via SMTP protocol, suitable for users with existing email services.
127
128
 
128
129
  [Resend](https://resend.com/) is a modern email API service with simple setup, recommended for new users.
129
130
 
130
- | Environment Variable | Type | Description | Example |
131
- | ------------------------ | ----------- | ---------------------------------------- | --------------------------- |
132
- | `EMAIL_SERVICE_PROVIDER` | Required | Set to `resend` | `resend` |
133
- | `RESEND_API_KEY` | Required | Resend API Key | `re_xxxxxxxxxxxxxxxxxxxxxx` |
134
- | `RESEND_FROM` | Recommended | Sender address, must be a verified domain| `noreply@your-domain.com` |
131
+ | Environment Variable | Type | Description | Example |
132
+ | ------------------------ | ----------- | ----------------------------------------- | --------------------------- |
133
+ | `EMAIL_SERVICE_PROVIDER` | Required | Set to `resend` | `resend` |
134
+ | `RESEND_API_KEY` | Required | Resend API Key | `re_xxxxxxxxxxxxxxxxxxxxxx` |
135
+ | `RESEND_FROM` | Recommended | Sender address, must be a verified domain | `noreply@your-domain.com` |
135
136
 
136
137
  <Callout type={'info'}>
137
138
  Before using Resend, you need to [verify your sending domain](https://resend.com/docs/dashboard/domains/introduction), otherwise emails can only be sent to your own address.
@@ -139,9 +140,9 @@ Send emails via SMTP protocol, suitable for users with existing email services.
139
140
 
140
141
  ### Common Configuration
141
142
 
142
- | Environment Variable | Type | Description | Example |
143
- | ------------------------- | -------- | -------------------------------------------------------- | ------- |
144
- | `AUTH_EMAIL_VERIFICATION` | Optional | Set to `1` to require email verification (off by default)| `1` |
143
+ | Environment Variable | Type | Description | Example |
144
+ | ------------------------- | -------- | --------------------------------------------------------- | ------- |
145
+ | `AUTH_EMAIL_VERIFICATION` | Optional | Set to `1` to require email verification (off by default) | `1` |
145
146
 
146
147
  ## Magic Link (Passwordless) Login
147
148
 
@@ -155,6 +156,19 @@ Enable magic-link login (depends on a working email provider above, off by defau
155
156
  Go to [Environment Variables](/docs/self-hosting/environment-variables/auth#better-auth) for detailed information on all Better Auth variables.
156
157
  </Callout>
157
158
 
159
+ ## Session Storage Configuration (Optional)
160
+
161
+ By default, Better Auth uses the database to store session data. You can configure Redis as secondary storage for better performance and cross-instance session sharing.
162
+
163
+ | Environment Variable | Type | Description |
164
+ | -------------------- | -------- | ------------------------------------------------------------ |
165
+ | `REDIS_URL` | Optional | Redis connection URL, enables Redis session storage when set |
166
+ | `REDIS_PREFIX` | Optional | Redis key prefix, defaults to `lobechat` |
167
+
168
+ <Callout type={'info'}>
169
+ When Redis is configured, authentication session data will be stored in Redis, enabling session sharing across multiple service instances and faster session validation. See [Redis Cache Service](/docs/self-hosting/advanced/redis) for detailed configuration.
170
+ </Callout>
171
+
158
172
  ## FAQ
159
173
 
160
174
  ### What SSO providers does Better Auth support?
@@ -164,3 +178,16 @@ Better Auth supports built-in providers (Google, GitHub, Microsoft, Apple, AWS C
164
178
  ### How do I enable multiple SSO providers?
165
179
 
166
180
  Set the `AUTH_SSO_PROVIDERS` environment variable with a comma-separated list, e.g., `google,github,microsoft`. The order determines the display order on the login page.
181
+
182
+ ### What if Casdoor users only have username without email?
183
+
184
+ The current authentication system requires email. Please configure a valid email address for users in Casdoor. Using a real, valid email is strongly recommended, otherwise features like password reset and magic link login will not work.
185
+
186
+ ### How do I restrict registration to specific emails or domains?
187
+
188
+ Set the `AUTH_ALLOWED_EMAILS` environment variable with a comma-separated list of allowed emails or domains. For example:
189
+
190
+ - Allow only `example.com` domain: `AUTH_ALLOWED_EMAILS=example.com`
191
+ - Allow multiple domains and specific emails: `AUTH_ALLOWED_EMAILS=example.com,company.org,admin@other.com`
192
+
193
+ Leave empty to allow all emails. This restriction applies to both email registration and SSO login.
@@ -107,14 +107,15 @@ LobeChat 使用 [Better Auth](https://www.better-auth.com) 作为身份验证解
107
107
 
108
108
  使用 SMTP 协议发送邮件,适合已有邮箱服务的用户。参考 [Nodemailer SMTP 文档](https://nodemailer.com/smtp/)。
109
109
 
110
- | 环境变量 | 类型 | 描述 | 示例 |
111
- | ------------------------- | -- | ----------------------------------------------- | ------------------ |
112
- | `EMAIL_SERVICE_PROVIDER` | 可选 | 设置为 `nodemailer`(默认值) | `nodemailer` |
113
- | `SMTP_HOST` | 必选 | SMTP 服务器主机名 | `smtp.gmail.com` |
114
- | `SMTP_PORT` | 必选 | SMTP 服务器端口(TLS 通常为 `587`,SSL 为 `465`) | `587` |
115
- | `SMTP_SECURE` | 可选 | SSL 设置为 `true`(端口 465),TLS 设置为 `false`(端口 587) | `false` |
116
- | `SMTP_USER` | 必选 | SMTP 认证用户名 | `user@gmail.com` |
117
- | `SMTP_PASS` | 必选 | SMTP 认证密码 | `your-app-password`|
110
+ | 环境变量 | 类型 | 描述 | 示例 |
111
+ | ------------------------ | -- | ---------------------------------------------- | ---------------------- |
112
+ | `EMAIL_SERVICE_PROVIDER` | 可选 | 设置为 `nodemailer`(默认值) | `nodemailer` |
113
+ | `SMTP_HOST` | 必选 | SMTP 服务器主机名 | `smtp.gmail.com` |
114
+ | `SMTP_PORT` | 必选 | SMTP 服务器端口(TLS 通常为 `587`,SSL 为 `465`) | `587` |
115
+ | `SMTP_SECURE` | 可选 | SSL 设置为 `true`(端口 465),TLS 设置为 `false`(端口 587) | `false` |
116
+ | `SMTP_USER` | 必选 | SMTP 认证用户名 | `user@gmail.com` |
117
+ | `SMTP_PASS` | 必选 | SMTP 认证密码 | `your-app-password` |
118
+ | `SMTP_FROM` | 可选 | 发件人地址(AWS SES 必填),默认为 `SMTP_USER` | `noreply@example.com` |
118
119
 
119
120
  <Callout type={'warning'}>
120
121
  使用 Gmail 时,需使用应用专用密码而非账户密码。前往 [Google 应用专用密码](https://myaccount.google.com/apppasswords) 生成。
@@ -124,11 +125,11 @@ LobeChat 使用 [Better Auth](https://www.better-auth.com) 作为身份验证解
124
125
 
125
126
  [Resend](https://resend.com/) 是一个现代邮件 API 服务,配置简单,推荐新用户使用。
126
127
 
127
- | 环境变量 | 类型 | 描述 | 示例 |
128
- | ------------------------- | -- | ---------------------------------- | --------------------------- |
129
- | `EMAIL_SERVICE_PROVIDER` | 必选 | 设置为 `resend` | `resend` |
130
- | `RESEND_API_KEY` | 必选 | Resend API Key | `re_xxxxxxxxxxxxxxxxxxxxxx` |
131
- | `RESEND_FROM` | 推荐 | 发件人地址,需为 Resend 已验证域名下的邮箱 | `noreply@your-domain.com` |
128
+ | 环境变量 | 类型 | 描述 | 示例 |
129
+ | ------------------------ | -- | ------------------------- | --------------------------- |
130
+ | `EMAIL_SERVICE_PROVIDER` | 必选 | 设置为 `resend` | `resend` |
131
+ | `RESEND_API_KEY` | 必选 | Resend API Key | `re_xxxxxxxxxxxxxxxxxxxxxx` |
132
+ | `RESEND_FROM` | 推荐 | 发件人地址,需为 Resend 已验证域名下的邮箱 | `noreply@your-domain.com` |
132
133
 
133
134
  <Callout type={'info'}>
134
135
  使用 Resend 前需先 [验证发件域名](https://resend.com/docs/dashboard/domains/introduction),否则只能发送到自己的邮箱。
@@ -136,9 +137,9 @@ LobeChat 使用 [Better Auth](https://www.better-auth.com) 作为身份验证解
136
137
 
137
138
  ### 通用配置
138
139
 
139
- | 环境变量 | 类型 | 描述 | 示例 |
140
- | ------------------------- | -- | ---------------------------- | -- |
141
- | `AUTH_EMAIL_VERIFICATION` | 可选 | 设置为 `1` 以要求用户在登录前验证邮箱(默认关闭) | `1`|
140
+ | 环境变量 | 类型 | 描述 | 示例 |
141
+ | ------------------------- | -- | --------------------------- | --- |
142
+ | `AUTH_EMAIL_VERIFICATION` | 可选 | 设置为 `1` 以要求用户在登录前验证邮箱(默认关闭) | `1` |
142
143
 
143
144
  ## 魔法链接(免密)登录
144
145
 
@@ -152,6 +153,19 @@ LobeChat 使用 [Better Auth](https://www.better-auth.com) 作为身份验证解
152
153
  前往 [环境变量](/zh/docs/self-hosting/environment-variables/auth#better-auth) 可查阅所有 Better Auth 相关变量详情。
153
154
  </Callout>
154
155
 
156
+ ## 会话存储配置(可选)
157
+
158
+ 默认情况下,Better Auth 使用数据库存储会话数据。你可以配置 Redis 作为二级存储,以获得更好的性能和跨实例会话共享能力。
159
+
160
+ | 环境变量 | 类型 | 描述 |
161
+ | -------------- | -- | ------------------------------- |
162
+ | `REDIS_URL` | 可选 | Redis 连接 URL,配置后自动启用 Redis 会话存储 |
163
+ | `REDIS_PREFIX` | 可选 | Redis 键前缀,默认为 `lobechat` |
164
+
165
+ <Callout type={'info'}>
166
+ 配置 Redis 后,认证会话数据将存储在 Redis 中,可以实现跨多个服务实例的会话共享,并提升会话验证速度。详细配置请参阅 [Redis 缓存服务](/zh/docs/self-hosting/advanced/redis)。
167
+ </Callout>
168
+
155
169
  ## 常见问题
156
170
 
157
171
  ### Better Auth 支持哪些 SSO 提供商?
@@ -161,3 +175,17 @@ Better Auth 支持内置提供商(Google、GitHub、Microsoft、Apple、AWS Co
161
175
  ### 如何启用多个 SSO 提供商?
162
176
 
163
177
  设置 `AUTH_SSO_PROVIDERS` 环境变量,使用逗号分隔多个提供商,例如 `google,github,microsoft`。顺序决定登录页面上的显示顺序。
178
+
179
+ ### Casdoor 用户只有 username 没有 email 怎么办?
180
+
181
+ 当前身份验证方案强依赖 email。请在 Casdoor 中为用户配置有效的 email 地址。
182
+ 强烈建议使用真实有效的邮箱,否则密码重置、魔法链接登录等功能将无法使用。
183
+
184
+ ### 如何限制只允许特定邮箱或域名注册?
185
+
186
+ 设置 `AUTH_ALLOWED_EMAILS` 环境变量,支持完整邮箱地址或域名,以逗号分隔。例如:
187
+
188
+ - 只允许 `example.com` 域名:`AUTH_ALLOWED_EMAILS=example.com`
189
+ - 允许多个域名和特定邮箱:`AUTH_ALLOWED_EMAILS=example.com,company.org,admin@other.com`
190
+
191
+ 留空表示允许所有邮箱注册。此限制对邮箱注册和 SSO 登录均有效。
@@ -0,0 +1,69 @@
1
+ ---
2
+ title: Configuring Upstash Redis Service
3
+ description: Step-by-step guide to configure Upstash Redis for LobeChat cache and session storage.
4
+ tags:
5
+ - Upstash
6
+ - Redis
7
+ - Cache
8
+ - Configuration Guide
9
+ ---
10
+
11
+ # Configuring Upstash Redis Service
12
+
13
+ [Upstash](https://upstash.com/) is a serverless Redis service that provides a free tier and pay-as-you-go pricing, making it ideal for LobeChat deployments.
14
+
15
+ ## Configuration Steps
16
+
17
+ <Steps>
18
+ ### Create Redis Database on Upstash
19
+
20
+ 1. Visit [Upstash Console](https://console.upstash.com/) and sign up
21
+ 2. Click **Create Database** and configure: name, region, enable TLS
22
+ 3. Copy the **Redis URL** (TCP connection, not REST API) from the database details page:
23
+
24
+ <Image alt={'Copy Redis URL from Upstash'} src={'https://hub-apac-1.lobeobjects.space/docs/43d110283ba816c0c2b45408e4f9d344.png'} />
25
+
26
+ ### Configure Environment Variables
27
+
28
+ ```shell
29
+ # Upstash Redis URL (copy from Upstash console)
30
+ REDIS_URL=rediss://default:xxxxxxxxxxxxx@us1-xxxxx-xxxxx.upstash.io:6379
31
+
32
+ # Optional: Enable TLS (recommended for Upstash)
33
+ REDIS_TLS=1
34
+
35
+ # Optional: Set a prefix for Redis keys
36
+ REDIS_PREFIX=lobechat
37
+ ```
38
+
39
+ <Callout type={'info'}>
40
+ Upstash uses `rediss://` (with double 's') for TLS connections. LobeChat supports this format automatically.
41
+ </Callout>
42
+ </Steps>
43
+
44
+ ## Environment Variables Overview
45
+
46
+ ```shell
47
+ # Upstash Redis Connection URL
48
+ REDIS_URL=rediss://default:xxxxxxxxxxxxx@us1-xxxxx-xxxxx.upstash.io:6379
49
+
50
+ # Optional: Enable TLS encryption (recommended for Upstash)
51
+ REDIS_TLS=1
52
+
53
+ # Optional: Key prefix for data isolation
54
+ REDIS_PREFIX=lobechat
55
+ ```
56
+
57
+ ## Notes
58
+
59
+ <Callout type={'tip'}>
60
+ Upstash offers a generous free tier with 10,000 commands per day, which is sufficient for personal use and small deployments.
61
+ </Callout>
62
+
63
+ <Callout type={'warning'}>
64
+ Make sure to keep your Redis URL secure and never expose it in client-side code or public repositories.
65
+ </Callout>
66
+
67
+ - **Free Tier Limits**: 10,000 commands/day, 256MB storage
68
+ - **TLS Required**: Upstash requires TLS connections, ensure `REDIS_TLS=1` is set
69
+ - **Regional vs Global**: Choose Global for better latency if your users are distributed worldwide
@@ -0,0 +1,69 @@
1
+ ---
2
+ title: 配置 Upstash Redis 服务
3
+ description: 详细指南:如何配置 Upstash Redis 用于 LobeChat 的缓存和会话存储。
4
+ tags:
5
+ - Upstash
6
+ - Redis
7
+ - 缓存
8
+ - 配置指南
9
+ ---
10
+
11
+ # 配置 Upstash Redis 服务
12
+
13
+ [Upstash](https://upstash.com/) 是一个 Serverless Redis 服务,提供免费额度和按量付费模式,非常适合 LobeChat 部署使用。
14
+
15
+ ## 配置步骤
16
+
17
+ <Steps>
18
+ ### 在 Upstash 创建 Redis 数据库
19
+
20
+ 1. 访问 [Upstash 控制台](https://console.upstash.com/) 并注册
21
+ 2. 点击 **Create Database**,配置:名称、区域、启用 TLS
22
+ 3. 从数据库详情页复制 **Redis URL**(TCP 连接方式,不是 REST API):
23
+
24
+ <Image alt={'从 Upstash 复制 Redis URL'} src={'https://hub-apac-1.lobeobjects.space/docs/43d110283ba816c0c2b45408e4f9d344.png'} />
25
+
26
+ ### 配置环境变量
27
+
28
+ ```shell
29
+ # Upstash Redis URL(从 Upstash 控制台复制)
30
+ REDIS_URL=rediss://default:xxxxxxxxxxxxx@us1-xxxxx-xxxxx.upstash.io:6379
31
+
32
+ # 可选:启用 TLS(Upstash 推荐)
33
+ REDIS_TLS=1
34
+
35
+ # 可选:设置 Redis 键前缀
36
+ REDIS_PREFIX=lobechat
37
+ ```
38
+
39
+ <Callout type={'info'}>
40
+ Upstash 使用 `rediss://`(双 's')表示 TLS 连接,LobeChat 自动支持此格式。
41
+ </Callout>
42
+ </Steps>
43
+
44
+ ## 环境变量概览
45
+
46
+ ```shell
47
+ # Upstash Redis 连接 URL
48
+ REDIS_URL=rediss://default:xxxxxxxxxxxxx@us1-xxxxx-xxxxx.upstash.io:6379
49
+
50
+ # 可选:启用 TLS 加密(Upstash 推荐)
51
+ REDIS_TLS=1
52
+
53
+ # 可选:键前缀,用于数据隔离
54
+ REDIS_PREFIX=lobechat
55
+ ```
56
+
57
+ ## 注意事项
58
+
59
+ <Callout type={'tip'}>
60
+ Upstash 提供慷慨的免费额度:每天 10,000 次命令,足够个人使用和小规模部署。
61
+ </Callout>
62
+
63
+ <Callout type={'warning'}>
64
+ 请确保安全保管你的 Redis URL,切勿在客户端代码或公开仓库中暴露。
65
+ </Callout>
66
+
67
+ - **免费额度限制**:每天 10,000 次命令,256MB 存储
68
+ - **TLS 必需**:Upstash 要求 TLS 连接,确保设置 `REDIS_TLS=1`
69
+ - **Regional vs Global**:如果用户分布全球,选择 Global 可获得更低延迟
@@ -0,0 +1,128 @@
1
+ ---
2
+ title: Configure Redis Cache Service
3
+ description: Learn how to configure Redis cache service to optimize LobeChat performance and session management.
4
+ tags:
5
+ - Redis
6
+ - Cache
7
+ - Session Storage
8
+ - Performance
9
+ ---
10
+
11
+ # Configure Redis Cache Service
12
+
13
+ LobeChat uses Redis as a high-performance cache and session storage service to optimize system performance and manage user authentication state.
14
+
15
+ <Callout type={'info'}>
16
+ LobeChat uses the standard Redis protocol (via ioredis library), supporting any Redis
17
+ protocol-compatible service, including official Redis, self-hosted Redis, and cloud provider Redis
18
+ services (such as AWS ElastiCache, Alibaba Cloud Redis, etc.).
19
+ </Callout>
20
+
21
+ ## Use Cases
22
+
23
+ Redis is used in LobeChat for the following scenarios:
24
+
25
+ ### Authentication Session Storage
26
+
27
+ As secondary storage for Better Auth, used to store user authentication sessions and token data. This enables:
28
+
29
+ - Sharing session state across multiple service instances
30
+ - Faster session validation
31
+ - Session revocation and management support
32
+
33
+ ### File Proxy Cache
34
+
35
+ Caches S3 presigned URLs to reduce S3 API calls and optimize file access performance.
36
+
37
+ ### Agent Configuration Cache
38
+
39
+ Caches Agent configuration data to reduce database queries and improve response speed.
40
+
41
+ ## Core Environment Variables
42
+
43
+ <Steps>
44
+ ### `REDIS_URL`
45
+
46
+ The Redis server connection URL. This is required to enable Redis functionality.
47
+
48
+ ```shell
49
+ REDIS_URL=redis://localhost:6379
50
+ ```
51
+
52
+ Supported URL formats:
53
+
54
+ - Standard: `redis://localhost:6379`
55
+ - With authentication: `redis://username:password@localhost:6379`
56
+ - With database: `redis://localhost:6379/0`
57
+
58
+ ### `REDIS_PREFIX`
59
+
60
+ The prefix for Redis keys, used to isolate LobeChat data in a shared Redis instance.
61
+
62
+ - Default: `lobechat`
63
+ - Example: `REDIS_PREFIX=my-lobechat`
64
+
65
+ ### `REDIS_TLS`
66
+
67
+ Whether to enable TLS/SSL encrypted connection.
68
+
69
+ - Default: `false`
70
+ - Example: `REDIS_TLS=true`
71
+
72
+ <Callout type={'tip'}>
73
+ If you use Redis services from cloud providers, you usually need to enable TLS to ensure secure
74
+ data transmission.
75
+ </Callout>
76
+
77
+ ### `REDIS_PASSWORD`
78
+
79
+ Redis authentication password (optional). Set this if your Redis server is configured with password authentication.
80
+
81
+ ### `REDIS_USERNAME`
82
+
83
+ Redis authentication username (optional). Redis 6.0+ supports ACL user authentication. Set this if using username authentication.
84
+
85
+ ### `REDIS_DATABASE`
86
+
87
+ Redis database index (optional). Redis supports multiple databases (default 0-15), you can specify which database to use.
88
+
89
+ - Default: `0`
90
+ - Example: `REDIS_DATABASE=1`
91
+ </Steps>
92
+
93
+ ## Configuration Examples
94
+
95
+ ### Local Development
96
+
97
+ ```shell
98
+ REDIS_URL=redis://localhost:6379
99
+ REDIS_PREFIX=lobechat-dev
100
+ ```
101
+
102
+ ### Production (with authentication)
103
+
104
+ ```shell
105
+ REDIS_URL=redis://localhost:6379
106
+ REDIS_PASSWORD=your-strong-password
107
+ REDIS_PREFIX=lobechat
108
+ REDIS_TLS=true
109
+ ```
110
+
111
+ ### Cloud Service (e.g., AWS ElastiCache)
112
+
113
+ ```shell
114
+ REDIS_URL=redis://your-cluster.cache.amazonaws.com:6379
115
+ REDIS_TLS=true
116
+ REDIS_PREFIX=lobechat
117
+ ```
118
+
119
+ ## Notes
120
+
121
+ <Callout type={'warning'}>
122
+ Redis is an optional service. If `REDIS_URL` is not configured, LobeChat will still function
123
+ normally, but will lose the caching and session management optimizations mentioned above.
124
+ </Callout>
125
+
126
+ - **Memory Management**: Redis is an in-memory database, ensure your server has sufficient memory
127
+ - **Persistence**: Enable Redis RDB or AOF persistence to prevent data loss
128
+ - **High Availability**: For production, consider using Redis Sentinel or Redis Cluster for high availability
@@ -0,0 +1,126 @@
1
+ ---
2
+ title: 配置 Redis 缓存服务
3
+ description: 了解如何配置 Redis 缓存服务以优化 LobeChat 的性能和会话管理。
4
+ tags:
5
+ - Redis
6
+ - 缓存
7
+ - 会话存储
8
+ - 性能优化
9
+ ---
10
+
11
+ # 配置 Redis 缓存服务
12
+
13
+ LobeChat 使用 Redis 作为高性能缓存和会话存储服务,用于优化系统性能和管理用户认证状态。
14
+
15
+ <Callout type={'info'}>
16
+ LobeChat 使用标准 Redis 协议(通过 ioredis 库),支持任何兼容 Redis 协议的服务,包括 Redis
17
+ 官方服务、自部署 Redis、以及云服务商提供的 Redis 服务(如 AWS ElastiCache、阿里云 Redis
18
+ 等)。
19
+ </Callout>
20
+
21
+ ## 使用场景
22
+
23
+ Redis 在 LobeChat 中主要用于以下场景:
24
+
25
+ ### 认证会话存储
26
+
27
+ 作为 Better Auth 的二级存储,用于存储用户认证 session 和 token 数据。这可以实现:
28
+
29
+ - 跨多个服务实例共享会话状态
30
+ - 更快的会话验证速度
31
+ - 支持会话撤销和管理
32
+
33
+ ### 文件代理缓存
34
+
35
+ 缓存 S3 预签名 URL,减少对 S3 API 的调用次数,优化文件访问性能。
36
+
37
+ ### Agent 配置缓存
38
+
39
+ 缓存 Agent 配置数据,减少数据库查询,提升响应速度。
40
+
41
+ ## 核心环境变量
42
+
43
+ <Steps>
44
+ ### `REDIS_URL`
45
+
46
+ Redis 服务器的连接 URL,这是启用 Redis 功能的必需配置。
47
+
48
+ ```shell
49
+ REDIS_URL=redis://localhost:6379
50
+ ```
51
+
52
+ 支持的 URL 格式:
53
+
54
+ - 标准格式:`redis://localhost:6379`
55
+ - 带认证:`redis://username:password@localhost:6379`
56
+ - 带数据库:`redis://localhost:6379/0`
57
+
58
+ ### `REDIS_PREFIX`
59
+
60
+ Redis 键的前缀,用于在共享 Redis 实例中隔离 LobeChat 的数据。
61
+
62
+ - 默认值:`lobechat`
63
+ - 示例:`REDIS_PREFIX=my-lobechat`
64
+
65
+ ### `REDIS_TLS`
66
+
67
+ 是否启用 TLS/SSL 加密连接。
68
+
69
+ - 默认值:`false`
70
+ - 示例:`REDIS_TLS=true`
71
+
72
+ <Callout type={'tip'}>
73
+ 如果你使用云服务商提供的 Redis 服务,通常需要启用 TLS 以确保数据传输安全。
74
+ </Callout>
75
+
76
+ ### `REDIS_PASSWORD`
77
+
78
+ Redis 认证密码(可选)。如果 Redis 服务器配置了密码认证,需要设置此变量。
79
+
80
+ ### `REDIS_USERNAME`
81
+
82
+ Redis 认证用户名(可选)。Redis 6.0+ 支持 ACL 用户认证,如果使用了用户名认证,需要设置此变量。
83
+
84
+ ### `REDIS_DATABASE`
85
+
86
+ Redis 数据库索引(可选)。Redis 支持多个数据库(默认 0-15),可以指定使用的数据库。
87
+
88
+ - 默认值:`0`
89
+ - 示例:`REDIS_DATABASE=1`
90
+ </Steps>
91
+
92
+ ## 配置示例
93
+
94
+ ### 本地开发
95
+
96
+ ```shell
97
+ REDIS_URL=redis://localhost:6379
98
+ REDIS_PREFIX=lobechat-dev
99
+ ```
100
+
101
+ ### 生产环境(带认证)
102
+
103
+ ```shell
104
+ REDIS_URL=redis://localhost:6379
105
+ REDIS_PASSWORD=your-strong-password
106
+ REDIS_PREFIX=lobechat
107
+ REDIS_TLS=true
108
+ ```
109
+
110
+ ### 云服务(如 AWS ElastiCache)
111
+
112
+ ```shell
113
+ REDIS_URL=redis://your-cluster.cache.amazonaws.com:6379
114
+ REDIS_TLS=true
115
+ REDIS_PREFIX=lobechat
116
+ ```
117
+
118
+ ## 注意事项
119
+
120
+ <Callout type={'warning'}>
121
+ Redis 是可选服务。如果不配置 `REDIS_URL`,LobeChat 仍然可以正常运行,但会失去上述缓存和会话管理的优化功能。
122
+ </Callout>
123
+
124
+ - **内存管理**:Redis 是内存数据库,请确保服务器有足够的内存
125
+ - **持久化**:建议启用 Redis 的 RDB 或 AOF 持久化,防止数据丢失
126
+ - **高可用**:生产环境建议使用 Redis Sentinel 或 Redis Cluster 实现高可用
@@ -27,7 +27,7 @@ LobeChat provides a complete authentication service capability when deployed. Th
27
27
  - Default: `-`
28
28
  - Example: `Tfhi2t2pelSMEA8eaV61KaqPNEndFFdMIxDaJnS1CUI=`
29
29
 
30
- #### `NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION`
30
+ #### `AUTH_EMAIL_VERIFICATION`
31
31
 
32
32
  - Type: Optional
33
33
  - Description: Set to `1` to require email verification before users can sign in. Users must verify their email address after registration.
@@ -41,6 +41,13 @@ LobeChat provides a complete authentication service capability when deployed. Th
41
41
  - Default: `-`
42
42
  - Example: `google,github,microsoft,cognito`
43
43
 
44
+ #### `AUTH_ALLOWED_EMAILS`
45
+
46
+ - Type: Optional
47
+ - Description: Comma-separated list of allowed emails or domains for registration. Supports full email addresses (e.g., `user@example.com`) or domain names (e.g., `example.com`). Leave empty to allow all emails.
48
+ - Default: `-`
49
+ - Example: `example.com,admin@other.com`
50
+
44
51
  #### `JWKS_KEY`
45
52
 
46
53
  - Type: Required
@@ -95,6 +102,13 @@ These settings are required for email verification and password reset features.
95
102
  - Default: `-`
96
103
  - Example: `your-app-specific-password`
97
104
 
105
+ #### `SMTP_FROM`
106
+
107
+ - Type: Optional
108
+ - Description: Sender email address. Required for AWS SES where `SMTP_USER` is not a valid email address. If not set, defaults to `SMTP_USER`.
109
+ - Default: Value of `SMTP_USER`
110
+ - Example: `noreply@example.com`
111
+
98
112
  ### Google
99
113
 
100
114
  #### `AUTH_GOOGLE_ID`
@@ -25,7 +25,7 @@ LobeChat 在部署时提供了完善的身份验证服务能力,以下是相
25
25
  - 默认值:`-`
26
26
  - 示例:`Tfhi2t2pelSMEA8eaV61KaqPNEndFFdMIxDaJnS1CUI=`
27
27
 
28
- #### `NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION`
28
+ #### `AUTH_EMAIL_VERIFICATION`
29
29
 
30
30
  - 类型:可选
31
31
  - 描述:设置为 `1` 以要求用户在登录前验证邮箱。用户注册后必须验证邮箱地址。
@@ -39,6 +39,13 @@ LobeChat 在部署时提供了完善的身份验证服务能力,以下是相
39
39
  - 默认值:`-`
40
40
  - 示例:`google,github,microsoft,cognito`
41
41
 
42
+ #### `AUTH_ALLOWED_EMAILS`
43
+
44
+ - 类型:可选
45
+ - 描述:允许注册的邮箱或域名白名单,以逗号分隔。支持完整邮箱地址(如 `user@example.com`)或域名(如 `example.com`)。留空表示允许所有邮箱。
46
+ - 默认值:`-`
47
+ - 示例:`example.com,admin@other.com`
48
+
42
49
  #### `JWKS_KEY`
43
50
 
44
51
  - 类型:必选
@@ -93,6 +100,13 @@ LobeChat 在部署时提供了完善的身份验证服务能力,以下是相
93
100
  - 默认值:`-`
94
101
  - 示例:`your-app-specific-password`
95
102
 
103
+ #### `SMTP_FROM`
104
+
105
+ - 类型:可选
106
+ - 描述:发件人邮箱地址。AWS SES 等服务需要此配置(因为 `SMTP_USER` 不是有效邮箱地址)。若未设置,默认使用 `SMTP_USER`。
107
+ - 默认值:`SMTP_USER` 的值
108
+ - 示例:`noreply@example.com`
109
+
96
110
  ### Google
97
111
 
98
112
  #### `AUTH_GOOGLE_ID`
@@ -19,6 +19,19 @@ LobeChat provides some additional configuration options during deployment, which
19
19
 
20
20
  ## Common Variables
21
21
 
22
+ ### `KEY_VAULTS_SECRET`
23
+
24
+ - Type: Required (server database mode)
25
+ - Description: Used to encrypt sensitive information stored by users in the database (such as API Keys, baseURL, etc.), preventing exposure of critical information in case of database breach
26
+ - Default: -
27
+ - Example: `Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ=`
28
+
29
+ <Callout type={'warning'}>
30
+ This key is used to encrypt sensitive data. Once set, do not change it, otherwise encrypted data cannot be decrypted.
31
+ </Callout>
32
+
33
+ <GenerateSecret envName="KEY_VAULTS_SECRET" />
34
+
22
35
  ### `API_KEY_SELECT_MODE`
23
36
 
24
37
  - Type:Optional