@lobehub/lobehub 2.0.0-next.123 → 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 (126) 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 +51 -0
  8. package/Dockerfile +6 -6
  9. package/GEMINI.md +63 -0
  10. package/README.md +8 -8
  11. package/README.zh-CN.md +8 -8
  12. package/changelog/v1.json +18 -0
  13. package/docs/development/database-schema.dbml +38 -0
  14. package/docs/self-hosting/advanced/auth.mdx +75 -2
  15. package/docs/self-hosting/advanced/auth.zh-CN.mdx +75 -2
  16. package/docs/self-hosting/environment-variables/auth.mdx +187 -1
  17. package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +187 -1
  18. package/locales/en-US/auth.json +93 -0
  19. package/locales/zh-CN/auth.json +107 -1
  20. package/package.json +5 -2
  21. package/packages/const/src/auth.ts +2 -1
  22. package/packages/database/migrations/0048_add_editor_data.sql +1 -0
  23. package/packages/database/migrations/0049_better_auth.sql +49 -0
  24. package/packages/database/migrations/meta/0048_snapshot.json +7913 -0
  25. package/packages/database/migrations/meta/0049_snapshot.json +8151 -0
  26. package/packages/database/migrations/meta/_journal.json +14 -0
  27. package/packages/database/src/core/migrations.json +19 -0
  28. package/packages/database/src/index.ts +1 -0
  29. package/packages/database/src/models/__tests__/session.test.ts +1 -2
  30. package/packages/database/src/models/user.ts +9 -8
  31. package/packages/database/src/repositories/tableViewer/index.test.ts +2 -2
  32. package/packages/database/src/schemas/agent.ts +1 -0
  33. package/packages/database/src/schemas/betterAuth.ts +63 -0
  34. package/packages/database/src/schemas/index.ts +1 -0
  35. package/packages/database/src/schemas/ragEvals.ts +1 -2
  36. package/packages/database/src/schemas/user.ts +3 -2
  37. package/packages/database/src/server/models/__tests__/user.test.ts +1 -4
  38. package/packages/types/src/user/preference.ts +11 -0
  39. package/packages/utils/src/server/__tests__/auth.test.ts +52 -0
  40. package/packages/utils/src/server/auth.ts +18 -1
  41. package/src/app/(backend)/api/auth/[...all]/route.ts +19 -0
  42. package/src/app/(backend)/api/auth/check-user/route.ts +62 -0
  43. package/src/app/(backend)/middleware/auth/index.ts +14 -0
  44. package/src/app/(backend)/middleware/auth/utils.test.ts +16 -0
  45. package/src/app/(backend)/middleware/auth/utils.ts +13 -10
  46. package/src/app/(backend)/webapi/chat/[provider]/route.test.ts +1 -0
  47. package/src/app/[variants]/(auth)/reset-password/layout.tsx +12 -0
  48. package/src/app/[variants]/(auth)/reset-password/page.tsx +209 -0
  49. package/src/app/[variants]/(auth)/signin/layout.tsx +12 -0
  50. package/src/app/[variants]/(auth)/signin/page.tsx +448 -0
  51. package/src/app/[variants]/(auth)/signup/[[...signup]]/BetterAuthSignUpForm.tsx +192 -0
  52. package/src/app/[variants]/(auth)/signup/[[...signup]]/page.tsx +31 -6
  53. package/src/app/[variants]/(auth)/verify-email/layout.tsx +12 -0
  54. package/src/app/[variants]/(auth)/verify-email/page.tsx +164 -0
  55. package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/UserBanner.test.tsx +12 -10
  56. package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +13 -11
  57. package/src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/TopicContent.tsx +15 -8
  58. package/src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/index.tsx +27 -30
  59. package/src/app/[variants]/(main)/profile/(home)/Client.tsx +306 -52
  60. package/src/app/[variants]/(main)/profile/(home)/features/SSOProvidersList/index.tsx +89 -47
  61. package/src/auth.ts +118 -0
  62. package/src/components/NextAuth/AuthIcons.tsx +3 -1
  63. package/src/envs/auth.ts +260 -13
  64. package/src/envs/email.ts +37 -0
  65. package/src/features/AgentSetting/AgentPlugin/index.tsx +6 -2
  66. package/src/features/User/UserPanel/PanelContent.tsx +6 -5
  67. package/src/features/User/__tests__/PanelContent.test.tsx +15 -6
  68. package/src/features/User/__tests__/UserAvatar.test.tsx +17 -6
  69. package/src/features/User/__tests__/useMenu.test.tsx +14 -12
  70. package/src/layout/AuthProvider/BetterAuth/UserUpdater.tsx +51 -0
  71. package/src/layout/AuthProvider/BetterAuth/index.tsx +14 -0
  72. package/src/layout/AuthProvider/index.tsx +3 -0
  73. package/src/layout/GlobalProvider/StoreInitialization.tsx +3 -3
  74. package/src/libs/better-auth/auth-client.ts +34 -0
  75. package/src/libs/better-auth/constants.ts +13 -0
  76. package/src/libs/better-auth/email-templates/index.ts +3 -0
  77. package/src/libs/better-auth/email-templates/magic-link.ts +98 -0
  78. package/src/libs/better-auth/email-templates/reset-password.ts +91 -0
  79. package/src/libs/better-auth/email-templates/verification.ts +108 -0
  80. package/src/libs/better-auth/sso/helpers.ts +61 -0
  81. package/src/libs/better-auth/sso/index.ts +113 -0
  82. package/src/libs/better-auth/sso/providers/auth0.ts +33 -0
  83. package/src/libs/better-auth/sso/providers/authelia.ts +35 -0
  84. package/src/libs/better-auth/sso/providers/authentik.ts +35 -0
  85. package/src/libs/better-auth/sso/providers/casdoor.ts +48 -0
  86. package/src/libs/better-auth/sso/providers/cloudflare-zero-trust.ts +41 -0
  87. package/src/libs/better-auth/sso/providers/cognito.ts +45 -0
  88. package/src/libs/better-auth/sso/providers/feishu.ts +181 -0
  89. package/src/libs/better-auth/sso/providers/generic-oidc.ts +44 -0
  90. package/src/libs/better-auth/sso/providers/github.ts +30 -0
  91. package/src/libs/better-auth/sso/providers/google.ts +30 -0
  92. package/src/libs/better-auth/sso/providers/keycloak.ts +35 -0
  93. package/src/libs/better-auth/sso/providers/logto.ts +38 -0
  94. package/src/libs/better-auth/sso/providers/microsoft.ts +65 -0
  95. package/src/libs/better-auth/sso/providers/okta.ts +37 -0
  96. package/src/libs/better-auth/sso/providers/wechat.ts +140 -0
  97. package/src/libs/better-auth/sso/providers/zitadel.ts +54 -0
  98. package/src/libs/better-auth/sso/types.ts +25 -0
  99. package/src/libs/better-auth/utils/client.ts +1 -0
  100. package/src/libs/better-auth/utils/common.ts +20 -0
  101. package/src/libs/better-auth/utils/server.test.ts +61 -0
  102. package/src/libs/better-auth/utils/server.ts +18 -0
  103. package/src/libs/trpc/lambda/context.test.ts +116 -0
  104. package/src/libs/trpc/lambda/context.ts +27 -0
  105. package/src/libs/trpc/middleware/userAuth.ts +4 -2
  106. package/src/locales/default/auth.ts +114 -1
  107. package/src/proxy.ts +71 -7
  108. package/src/server/globalConfig/index.ts +12 -1
  109. package/src/server/routers/lambda/user.ts +4 -0
  110. package/src/server/services/email/README.md +241 -0
  111. package/src/server/services/email/impls/index.test.ts +39 -0
  112. package/src/server/services/email/impls/index.ts +32 -0
  113. package/src/server/services/email/impls/nodemailer/index.ts +108 -0
  114. package/src/server/services/email/impls/nodemailer/type.ts +31 -0
  115. package/src/server/services/email/impls/type.ts +61 -0
  116. package/src/server/services/email/index.test.ts +144 -0
  117. package/src/server/services/email/index.ts +40 -0
  118. package/src/services/user/index.test.ts +162 -2
  119. package/src/services/user/index.ts +6 -3
  120. package/src/store/aiInfra/slices/aiProvider/action.ts +4 -4
  121. package/src/store/user/slices/auth/action.test.ts +213 -16
  122. package/src/store/user/slices/auth/action.ts +86 -1
  123. package/src/store/user/slices/auth/initialState.ts +13 -2
  124. package/src/store/user/slices/auth/selectors.ts +6 -2
  125. package/src/store/user/slices/common/action.ts +5 -1
  126. package/src/app/(backend)/api/auth/[...nextauth]/route.ts +0 -3
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/README.md CHANGED
@@ -345,14 +345,14 @@ In addition, these plugins are not limited to news aggregation, but can also ext
345
345
 
346
346
  <!-- PLUGIN LIST -->
347
347
 
348
- | Recent Submits | Description |
349
- | -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
350
- | [SEO](https://lobechat.com/discover/plugin/SEO)<br/><sup>By **orrenprunckun** on **2025-11-14**</sup> | Enter any URL and keyword and get an On-Page SEO analysis & insights!<br/>`seo` |
351
- | [Shopping tools](https://lobechat.com/discover/plugin/ShoppingTools)<br/><sup>By **shoppingtools** on **2025-10-27**</sup> | Search for products on eBay & AliExpress, find eBay events & coupons. Get prompt examples.<br/>`shopping` `e-bay` `ali-express` `coupons` |
352
- | [PortfolioMeta](https://lobechat.com/discover/plugin/StockData)<br/><sup>By **portfoliometa** on **2025-09-27**</sup> | Analyze stocks and get comprehensive real-time investment data and analytics.<br/>`stock` |
353
- | [Web](https://lobechat.com/discover/plugin/web)<br/><sup>By **Proghit** on **2025-01-24**</sup> | Smart web search that reads and analyzes pages to deliver comprehensive answers from Google results.<br/>`web` `search` |
354
-
355
- > 📊 Total plugins: [<kbd>**42**</kbd>](https://lobechat.com/discover/plugins)
348
+ | Recent Submits | Description |
349
+ | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
350
+ | [SEO](https://lobechat.com/discover/plugin/SEO)<br/><sup>By **orrenprunckun** on **2025-11-14**</sup> | Enter any URL and keyword and get an On-Page SEO analysis & insights!<br/>`seo` |
351
+ | [Shopping tools](https://lobechat.com/discover/plugin/ShoppingTools)<br/><sup>By **shoppingtools** on **2025-10-27**</sup> | Search for products on eBay & AliExpress, find eBay events & coupons. Get prompt examples.<br/>`shopping` `e-bay` `ali-express` `coupons` |
352
+ | [Web](https://lobechat.com/discover/plugin/web)<br/><sup>By **Proghit** on **2025-01-24**</sup> | Smart web search that reads and analyzes pages to deliver comprehensive answers from Google results.<br/>`web` `search` |
353
+ | [Bing_websearch](https://lobechat.com/discover/plugin/Bingsearch-identifier)<br/><sup>By **FineHow** on **2024-12-22**</sup> | Search for information from the internet base BingApi<br/>`bingsearch` |
354
+
355
+ > 📊 Total plugins: [<kbd>**41**</kbd>](https://lobechat.com/discover/plugins)
356
356
 
357
357
  <!-- PLUGIN LIST -->
358
358
 
package/README.zh-CN.md CHANGED
@@ -338,14 +338,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
338
338
 
339
339
  <!-- PLUGIN LIST -->
340
340
 
341
- | 最近新增 | 描述 |
342
- | --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
343
- | [SEO](https://lobechat.com/discover/plugin/SEO)<br/><sup>By **orrenprunckun** on **2025-11-14**</sup> | 输入任何 URL 和关键词,获取页面 SEO 分析和见解!<br/>`seo` |
344
- | [购物工具](https://lobechat.com/discover/plugin/ShoppingTools)<br/><sup>By **shoppingtools** on **2025-10-27**</sup> | 在 eBay 和 AliExpress 上搜索产品,查找 eBay 活动和优惠券。获取快速示例。<br/>`购物` `e-bay` `ali-express` `优惠券` |
345
- | [PortfolioMeta](https://lobechat.com/discover/plugin/StockData)<br/><sup>By **portfoliometa** on **2025-09-27**</sup> | 分析股票并获取全面的实时投资数据和分析。<br/>`股票` |
346
- | [网页](https://lobechat.com/discover/plugin/web)<br/><sup>By **Proghit** on **2025-01-24**</sup> | 智能网页搜索,读取和分析页面,以提供来自 Google 结果的全面答案。<br/>`网页` `搜索` |
347
-
348
- > 📊 Total plugins: [<kbd>**42**</kbd>](https://lobechat.com/discover/plugins)
341
+ | 最近新增 | 描述 |
342
+ | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
343
+ | [SEO](https://lobechat.com/discover/plugin/SEO)<br/><sup>By **orrenprunckun** on **2025-11-14**</sup> | 输入任何 URL 和关键词,获取页面 SEO 分析和见解!<br/>`seo` |
344
+ | [购物工具](https://lobechat.com/discover/plugin/ShoppingTools)<br/><sup>By **shoppingtools** on **2025-10-27**</sup> | 在 eBay 和 AliExpress 上搜索产品,查找 eBay 活动和优惠券。获取快速示例。<br/>`购物` `e-bay` `ali-express` `优惠券` |
345
+ | [网页](https://lobechat.com/discover/plugin/web)<br/><sup>By **Proghit** on **2025-01-24**</sup> | 智能网页搜索,读取和分析页面,以提供来自 Google 结果的全面答案。<br/>`网页` `搜索` |
346
+ | [必应网页搜索](https://lobechat.com/discover/plugin/Bingsearch-identifier)<br/><sup>By **FineHow** on **2024-12-22**</sup> | 通过 BingApi 搜索互联网上的信息<br/>`bingsearch` |
347
+
348
+ > 📊 Total plugins: [<kbd>**41**</kbd>](https://lobechat.com/discover/plugins)
349
349
 
350
350
  <!-- PLUGIN LIST -->
351
351
 
package/changelog/v1.json CHANGED
@@ -1,4 +1,22 @@
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
+ },
11
+ {
12
+ "children": {
13
+ "fixes": [
14
+ "Fixed the agent settings plugins pages error problem, improve topic item interaction and editing behavior."
15
+ ]
16
+ },
17
+ "date": "2025-11-27",
18
+ "version": "2.0.0-next.124"
19
+ },
2
20
  {
3
21
  "children": {
4
22
  "improvements": [
@@ -4,6 +4,7 @@ table agents {
4
4
  title varchar(255)
5
5
  description varchar(1000)
6
6
  tags jsonb [default: `[]`]
7
+ editor_data jsonb
7
8
  avatar text
8
9
  background_color text
9
10
  market_identifier text
@@ -136,6 +137,42 @@ table async_tasks {
136
137
  updated_at "timestamp with time zone" [not null, default: `now()`]
137
138
  }
138
139
 
140
+ table accounts {
141
+ access_token text
142
+ access_token_expires_at timestamp
143
+ account_id text [not null]
144
+ created_at timestamp [not null, default: `now()`]
145
+ id text [pk, not null]
146
+ id_token text
147
+ password text
148
+ provider_id text [not null]
149
+ refresh_token text
150
+ refresh_token_expires_at timestamp
151
+ scope text
152
+ updated_at timestamp [not null]
153
+ user_id text [not null]
154
+ }
155
+
156
+ table auth_sessions {
157
+ created_at timestamp [not null, default: `now()`]
158
+ expires_at timestamp [not null]
159
+ id text [pk, not null]
160
+ ip_address text
161
+ token text [not null, unique]
162
+ updated_at timestamp [not null]
163
+ user_agent text
164
+ user_id text [not null]
165
+ }
166
+
167
+ table verifications {
168
+ created_at timestamp [not null, default: `now()`]
169
+ expires_at timestamp [not null]
170
+ id text [pk, not null]
171
+ identifier text [not null]
172
+ updated_at timestamp [not null, default: `now()`]
173
+ value text [not null]
174
+ }
175
+
139
176
  table chat_groups {
140
177
  id text [pk, not null]
141
178
  title text
@@ -980,6 +1017,7 @@ table users {
980
1017
  full_name text
981
1018
  is_onboarded boolean [default: false]
982
1019
  clerk_created_at "timestamp with time zone"
1020
+ email_verified boolean [not null, default: false]
983
1021
  email_verified_at "timestamp with time zone"
984
1022
  preference jsonb
985
1023
  accessed_at "timestamp with time zone" [not null, default: `now()`]
@@ -1,10 +1,11 @@
1
1
  ---
2
2
  title: LobeChat Authentication Service Configuration
3
3
  description: >-
4
- Learn how to configure external authentication services using Clerk or Next Auth for centralized user authorization management. Supported authentication services include Auth0, Azure ID, etc.
4
+ Learn how to configure external authentication services using Better Auth, Clerk, or Next Auth for centralized user authorization management. Supported authentication services include Auth0, Azure ID, etc.
5
5
 
6
6
  tags:
7
7
  - Authentication Service
8
+ - Better Auth
8
9
  - Next Auth
9
10
  - SSO
10
11
  - Clerk
@@ -12,7 +13,7 @@ tags:
12
13
 
13
14
  # Authentication Service
14
15
 
15
- LobeChat supports the configuration of external authentication services using Clerk or Next Auth for internal use within enterprises/organizations to centrally manage user authorization.
16
+ LobeChat supports the configuration of external authentication services using Better Auth, Clerk, or Next Auth for internal use within enterprises/organizations to centrally manage user authorization.
16
17
 
17
18
  ## Clerk
18
19
 
@@ -22,6 +23,78 @@ LobeChat has deeply integrated with Clerk to provide users with a more secure an
22
23
 
23
24
  By setting the environment variables `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` and `CLERK_SECRET_KEY` in LobeChat's environment, you can enable and use Clerk.
24
25
 
26
+ ## Better Auth
27
+
28
+ [Better Auth](https://www.better-auth.com) is a modern, framework-agnostic authentication library designed to provide comprehensive, secure, and flexible authentication solutions. It supports various authentication methods including email/password, magic links, and multiple OAuth/SSO providers.
29
+
30
+ ### Key Features
31
+
32
+ - **Email/Password Authentication**: Built-in support for traditional email and password login with secure password hashing
33
+ - **Email Verification**: Optional email verification flow with customizable email templates
34
+ - **Magic Link Login**: Passwordless authentication via email magic links
35
+ - **OAuth/SSO Support**: Integration with popular identity providers including Google, GitHub, Microsoft, AWS Cognito, and more
36
+ - **Generic OIDC/OAuth**: Support for any OpenID Connect or OAuth 2.0 compliant provider
37
+
38
+ ### Getting Started
39
+
40
+ To enable Better Auth in LobeChat, set the following environment variables:
41
+
42
+ | Environment Variable | Type | Description |
43
+ | -------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------- |
44
+ | `NEXT_PUBLIC_ENABLE_BETTER_AUTH` | Required | Set to `1` to enable Better Auth service |
45
+ | `AUTH_SECRET` | Required | Key used to encrypt session tokens. Generate using: `openssl rand -base64 32` |
46
+ | `NEXT_PUBLIC_AUTH_URL` | Optional | The URL accessible from the browser for Better Auth callbacks. Only set this if the default generated URL is incorrect |
47
+ | `AUTH_SSO_PROVIDERS` | Optional | Comma-separated list of enabled SSO providers, e.g., `google,github,microsoft` |
48
+
49
+ ### Supported SSO Providers
50
+
51
+ | Provider | Value | Environment Variables |
52
+ | --------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------- |
53
+ | Google | `google` | `AUTH_GOOGLE_ID`, `AUTH_GOOGLE_SECRET` |
54
+ | GitHub | `github` | `AUTH_GITHUB_ID`, `AUTH_GITHUB_SECRET` |
55
+ | Microsoft | `microsoft` | `AUTH_MICROSOFT_ID`, `AUTH_MICROSOFT_SECRET` |
56
+ | AWS Cognito | `cognito` | `AUTH_COGNITO_ID`, `AUTH_COGNITO_SECRET`, `AUTH_COGNITO_ISSUER` |
57
+ | Auth0 | `auth0` | `AUTH_AUTH0_ID`, `AUTH_AUTH0_SECRET`, `AUTH_AUTH0_ISSUER` |
58
+ | Authelia | `authelia` | `AUTH_AUTHELIA_ID`, `AUTH_AUTHELIA_SECRET`, `AUTH_AUTHELIA_ISSUER` |
59
+ | Authentik | `authentik` | `AUTH_AUTHENTIK_ID`, `AUTH_AUTHENTIK_SECRET`, `AUTH_AUTHENTIK_ISSUER` |
60
+ | Casdoor | `casdoor` | `AUTH_CASDOOR_ID`, `AUTH_CASDOOR_SECRET`, `AUTH_CASDOOR_ISSUER` |
61
+ | Cloudflare Zero Trust | `cloudflare-zero-trust` | `AUTH_CLOUDFLARE_ZERO_TRUST_ID`, `AUTH_CLOUDFLARE_ZERO_TRUST_SECRET`, `AUTH_CLOUDFLARE_ZERO_TRUST_ISSUER` |
62
+ | Keycloak | `keycloak` | `AUTH_KEYCLOAK_ID`, `AUTH_KEYCLOAK_SECRET`, `AUTH_KEYCLOAK_ISSUER` |
63
+ | Logto | `logto` | `AUTH_LOGTO_ID`, `AUTH_LOGTO_SECRET`, `AUTH_LOGTO_ISSUER` |
64
+ | Okta | `okta` | `AUTH_OKTA_ID`, `AUTH_OKTA_SECRET`, `AUTH_OKTA_ISSUER` |
65
+ | ZITADEL | `zitadel` | `AUTH_ZITADEL_ID`, `AUTH_ZITADEL_SECRET`, `AUTH_ZITADEL_ISSUER` |
66
+ | Generic OIDC | `generic-oidc` | `AUTH_GENERIC_OIDC_ID`, `AUTH_GENERIC_OIDC_SECRET`, `AUTH_GENERIC_OIDC_ISSUER` |
67
+ | Feishu | `feishu` | `AUTH_FEISHU_APP_ID`, `AUTH_FEISHU_APP_SECRET` |
68
+ | WeChat | `wechat` | `AUTH_WECHAT_ID`, `AUTH_WECHAT_SECRET` |
69
+
70
+ ### Callback URL Format
71
+
72
+ When configuring OAuth providers, use the following callback URL format:
73
+
74
+ - **Development**: `http://localhost:3210/api/auth/callback/{provider}`
75
+ - **Production**: `https://yourdomain.com/api/auth/callback/{provider}`
76
+
77
+ ### Email Service Configuration
78
+
79
+ If you want to enable email verification or password reset features, you need to configure SMTP settings:
80
+
81
+ | Environment Variable | Type | Description |
82
+ | ------------------------------------- | -------- | ----------------------------------------------------------------- |
83
+ | `NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION` | Optional | Set to `1` to require email verification before users can sign in |
84
+ | `SMTP_HOST` | Required | SMTP server hostname (e.g., `smtp.gmail.com`) |
85
+ | `SMTP_PORT` | Required | SMTP server port (usually `587` for TLS, `465` for SSL) |
86
+ | `SMTP_SECURE` | Optional | Set to `true` for SSL (port 465), `false` for TLS (port 587) |
87
+ | `SMTP_USER` | Required | SMTP authentication username |
88
+ | `SMTP_PASS` | Required | SMTP authentication password |
89
+
90
+ <Callout type={'tip'}>
91
+ For detailed provider configuration, refer to the [Next Auth provider documentation](/docs/self-hosting/advanced/auth/next-auth) as most configurations are compatible, or visit the official [Better Auth documentation](https://www.better-auth.com/docs/introduction).
92
+ </Callout>
93
+
94
+ <Callout type={'tip'}>
95
+ Go to [📘 Environment Variables](/docs/self-hosting/environment-variables/auth#better-auth) for detailed information on all Better Auth variables.
96
+ </Callout>
97
+
25
98
  ## Next Auth
26
99
 
27
100
  Before using NextAuth, please set the following variables in LobeChat's environment variables:
@@ -1,8 +1,9 @@
1
1
  ---
2
2
  title: LobeChat 身份验证服务配置
3
- description: 了解如何使用 Clerk 或 Next Auth 配置外部身份验证服务,以统一管理用户授权。支持的身份验证服务包括 Auth0、 Azure ID 等。
3
+ description: 了解如何使用 Better Auth、Clerk 或 Next Auth 配置外部身份验证服务,以统一管理用户授权。支持的身份验证服务包括 Auth0、 Azure ID 等。
4
4
  tags:
5
5
  - 身份验证服务
6
+ - Better Auth
6
7
  - LobeChat
7
8
  - SSO
8
9
  - Clerk
@@ -10,7 +11,7 @@ tags:
10
11
 
11
12
  # 身份验证服务
12
13
 
13
- LobeChat 支持使用 Clerk 或者 Next Auth 配置外部身份验证服务,供企业 / 组织内部使用,统一管理用户授权。
14
+ LobeChat 支持使用 Better Auth、Clerk 或者 Next Auth 配置外部身份验证服务,供企业 / 组织内部使用,统一管理用户授权。
14
15
 
15
16
  ## Clerk
16
17
 
@@ -20,6 +21,78 @@ LobeChat 与 Clerk 做了深度集成,能够为用户提供一个更加安全
20
21
 
21
22
  在 LobeChat 的环境变量中设置 `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` 和 `CLERK_SECRET_KEY`,即可开启和使用 Clerk。
22
23
 
24
+ ## Better Auth
25
+
26
+ [Better Auth](https://www.better-auth.com) 是一个现代化、框架无关的身份验证库,旨在提供全面、安全、灵活的身份验证解决方案。它支持多种认证方式,包括邮箱 / 密码登录、魔法链接登录以及多种 OAuth/SSO 提供商。
27
+
28
+ ### 主要特性
29
+
30
+ - **邮箱 / 密码认证**:内置支持传统的邮箱和密码登录,采用安全的密码哈希算法
31
+ - **邮箱验证**:可选的邮箱验证流程,支持自定义邮件模板
32
+ - **魔法链接登录**:通过邮件魔法链接实现无密码认证
33
+ - **OAuth/SSO 支持**:集成 Google、GitHub、Microsoft、AWS Cognito 等主流身份提供商
34
+ - **通用 OIDC/OAuth**:支持任何符合 OpenID Connect 或 OAuth 2.0 标准的提供商
35
+
36
+ ### 快速开始
37
+
38
+ 要在 LobeChat 中启用 Better Auth,请设置以下环境变量:
39
+
40
+ | 环境变量 | 类型 | 描述 |
41
+ | -------------------------------- | -- | ------------------------------------------------ |
42
+ | `NEXT_PUBLIC_ENABLE_BETTER_AUTH` | 必选 | 设置为 `1` 以启用 Better Auth 服务 |
43
+ | `AUTH_SECRET` | 必选 | 用于加密会话令牌的密钥。使用以下命令生成:`openssl rand -base64 32` |
44
+ | `NEXT_PUBLIC_AUTH_URL` | 可选 | 浏览器可访问的 Better Auth 回调 URL。仅在默认生成的 URL 不正确时设置 |
45
+ | `AUTH_SSO_PROVIDERS` | 可选 | 启用的 SSO 提供商列表,以逗号分隔,例如 `google,github,microsoft` |
46
+
47
+ ### 支持的 SSO 提供商
48
+
49
+ | 提供商 | 值 | 环境变量 |
50
+ | --------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------- |
51
+ | Google | `google` | `AUTH_GOOGLE_ID`, `AUTH_GOOGLE_SECRET` |
52
+ | GitHub | `github` | `AUTH_GITHUB_ID`, `AUTH_GITHUB_SECRET` |
53
+ | Microsoft | `microsoft` | `AUTH_MICROSOFT_ID`, `AUTH_MICROSOFT_SECRET` |
54
+ | AWS Cognito | `cognito` | `AUTH_COGNITO_ID`, `AUTH_COGNITO_SECRET`, `AUTH_COGNITO_ISSUER` |
55
+ | Auth0 | `auth0` | `AUTH_AUTH0_ID`, `AUTH_AUTH0_SECRET`, `AUTH_AUTH0_ISSUER` |
56
+ | Authelia | `authelia` | `AUTH_AUTHELIA_ID`, `AUTH_AUTHELIA_SECRET`, `AUTH_AUTHELIA_ISSUER` |
57
+ | Authentik | `authentik` | `AUTH_AUTHENTIK_ID`, `AUTH_AUTHENTIK_SECRET`, `AUTH_AUTHENTIK_ISSUER` |
58
+ | Casdoor | `casdoor` | `AUTH_CASDOOR_ID`, `AUTH_CASDOOR_SECRET`, `AUTH_CASDOOR_ISSUER` |
59
+ | Cloudflare Zero Trust | `cloudflare-zero-trust` | `AUTH_CLOUDFLARE_ZERO_TRUST_ID`, `AUTH_CLOUDFLARE_ZERO_TRUST_SECRET`, `AUTH_CLOUDFLARE_ZERO_TRUST_ISSUER` |
60
+ | Keycloak | `keycloak` | `AUTH_KEYCLOAK_ID`, `AUTH_KEYCLOAK_SECRET`, `AUTH_KEYCLOAK_ISSUER` |
61
+ | Logto | `logto` | `AUTH_LOGTO_ID`, `AUTH_LOGTO_SECRET`, `AUTH_LOGTO_ISSUER` |
62
+ | Okta | `okta` | `AUTH_OKTA_ID`, `AUTH_OKTA_SECRET`, `AUTH_OKTA_ISSUER` |
63
+ | ZITADEL | `zitadel` | `AUTH_ZITADEL_ID`, `AUTH_ZITADEL_SECRET`, `AUTH_ZITADEL_ISSUER` |
64
+ | Generic OIDC | `generic-oidc` | `AUTH_GENERIC_OIDC_ID`, `AUTH_GENERIC_OIDC_SECRET`, `AUTH_GENERIC_OIDC_ISSUER` |
65
+ | 飞书 | `feishu` | `AUTH_FEISHU_APP_ID`, `AUTH_FEISHU_APP_SECRET` |
66
+ | 微信 | `wechat` | `AUTH_WECHAT_ID`, `AUTH_WECHAT_SECRET` |
67
+
68
+ ### 回调 URL 格式
69
+
70
+ 配置 OAuth 提供商时,请使用以下回调 URL 格式:
71
+
72
+ - **开发环境**:`http://localhost:3210/api/auth/callback/{provider}`
73
+ - **生产环境**:`https://yourdomain.com/api/auth/callback/{provider}`
74
+
75
+ ### 邮件服务配置
76
+
77
+ 如果需要启用邮箱验证或密码重置功能,需要配置 SMTP 设置:
78
+
79
+ | 环境变量 | 类型 | 描述 |
80
+ | ------------------------------------- | -- | ---------------------------------------------- |
81
+ | `NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION` | 可选 | 设置为 `1` 以要求用户在登录前验证邮箱 |
82
+ | `SMTP_HOST` | 必选 | SMTP 服务器主机名(例如 `smtp.gmail.com`) |
83
+ | `SMTP_PORT` | 必选 | SMTP 服务器端口(TLS 通常为 `587`,SSL 为 `465`) |
84
+ | `SMTP_SECURE` | 可选 | SSL 设置为 `true`(端口 465),TLS 设置为 `false`(端口 587) |
85
+ | `SMTP_USER` | 必选 | SMTP 认证用户名 |
86
+ | `SMTP_PASS` | 必选 | SMTP 认证密码 |
87
+
88
+ <Callout type={'tip'}>
89
+ 详细的提供商配置可参考 [Next Auth 提供商文档](/zh/docs/self-hosting/advanced/auth/next-auth)(大部分配置兼容),或访问官方 [Better Auth 文档](https://www.better-auth.com/docs/introduction)。
90
+ </Callout>
91
+
92
+ <Callout type={'tip'}>
93
+ 前往 [📘 环境变量](/zh/docs/self-hosting/environment-variables/auth#better-auth) 可查阅所有 Better Auth 相关变量详情。
94
+ </Callout>
95
+
23
96
  ## Next Auth
24
97
 
25
98
  在使用 NextAuth 之前,请先在 LobeChat 的环境变量中设置以下变量:
@@ -1,11 +1,12 @@
1
1
  ---
2
2
  title: LobeChat Authentication Service Environment Variables
3
3
  description: >-
4
- Explore the essential environment variables for configuring authentication services in LobeChat, including OAuth SSO, NextAuth settings, and provider-specific details.
4
+ Explore the essential environment variables for configuring authentication services in LobeChat, including Better Auth, OAuth SSO, NextAuth settings, and provider-specific details.
5
5
 
6
6
 
7
7
  tags:
8
8
  - Authentication Service
9
+ - Better Auth
9
10
  - OAuth SSO
10
11
  - Clerk
11
12
  - NextAuth
@@ -15,6 +16,191 @@ tags:
15
16
 
16
17
  LobeChat provides a complete authentication service capability when deployed. The following are the relevant environment variables. You can use these environment variables to easily define the identity verification services that need to be enabled in LobeChat.
17
18
 
19
+ ## Better Auth
20
+
21
+ ### General Settings
22
+
23
+ #### `NEXT_PUBLIC_ENABLE_BETTER_AUTH`
24
+
25
+ - Type: Required
26
+ - Description: Set to `1` to enable Better Auth service. When enabled, Better Auth will be used for authentication instead of Next Auth or Clerk.
27
+ - Default: `-`
28
+ - Example: `1`
29
+
30
+ #### `AUTH_SECRET`
31
+
32
+ - Type: Required
33
+ - Description: Key used to encrypt session tokens. Shared between Better Auth and Next Auth. You can generate the key using the command: `openssl rand -base64 32`.
34
+ - Default: `-`
35
+ - Example: `Tfhi2t2pelSMEA8eaV61KaqPNEndFFdMIxDaJnS1CUI=`
36
+
37
+ #### `NEXT_PUBLIC_AUTH_URL`
38
+
39
+ - Type: Optional
40
+ - Description: The URL accessible from the browser for Better Auth callbacks. Only set this if the default generated URL is incorrect.
41
+ - Default: `-`
42
+ - Example: `https://example.com`
43
+
44
+ #### `NEXT_PUBLIC_AUTH_EMAIL_VERIFICATION`
45
+
46
+ - Type: Optional
47
+ - Description: Set to `1` to require email verification before users can sign in. Users must verify their email address after registration.
48
+ - Default: `0`
49
+ - Example: `1`
50
+
51
+ #### `AUTH_SSO_PROVIDERS`
52
+
53
+ - Type: Optional
54
+ - Description: Comma-separated list of enabled SSO providers. The order determines the display order of providers on the login page.
55
+ - Default: `-`
56
+ - Example: `google,github,microsoft,cognito`
57
+
58
+ ### Email Service (SMTP)
59
+
60
+ These settings are required for email verification and password reset features.
61
+
62
+ #### `SMTP_HOST`
63
+
64
+ - Type: Required (for email features)
65
+ - Description: SMTP server hostname.
66
+ - Default: `-`
67
+ - Example: `smtp.gmail.com`
68
+
69
+ #### `SMTP_PORT`
70
+
71
+ - Type: Required (for email features)
72
+ - Description: SMTP server port. Usually `587` for TLS or `465` for SSL.
73
+ - Default: `-`
74
+ - Example: `587`
75
+
76
+ #### `SMTP_SECURE`
77
+
78
+ - Type: Optional
79
+ - Description: Use secure connection. Set to `true` for port 465 (SSL), `false` for port 587 (TLS).
80
+ - Default: `false`
81
+ - Example: `false`
82
+
83
+ #### `SMTP_USER`
84
+
85
+ - Type: Required (for email features)
86
+ - Description: SMTP authentication username, usually your email address.
87
+ - Default: `-`
88
+ - Example: `your-email@example.com`
89
+
90
+ #### `SMTP_PASS`
91
+
92
+ - Type: Required (for email features)
93
+ - Description: SMTP authentication password. For Gmail, use an app-specific password.
94
+ - Default: `-`
95
+ - Example: `your-app-specific-password`
96
+
97
+ ### Google
98
+
99
+ #### `AUTH_GOOGLE_ID`
100
+
101
+ - Type: Required
102
+ - Description: Client ID of the Google OAuth application. Get it from [Google Cloud Console](https://console.cloud.google.com/apis/credentials).
103
+ - Default: `-`
104
+ - Example: `123456789.apps.googleusercontent.com`
105
+
106
+ #### `AUTH_GOOGLE_SECRET`
107
+
108
+ - Type: Required
109
+ - Description: Client Secret of the Google OAuth application.
110
+ - Default: `-`
111
+ - Example: `GOCSPX-xxxxxxxxxxxxxxxxxxxx`
112
+
113
+ ### GitHub
114
+
115
+ #### `AUTH_GITHUB_ID`
116
+
117
+ - Type: Required
118
+ - Description: Client ID of the GitHub OAuth application. Get it from [GitHub Developer Settings](https://github.com/settings/developers).
119
+ - Default: `-`
120
+ - Example: `Ov23xxxxxxxxxxxxx`
121
+
122
+ #### `AUTH_GITHUB_SECRET`
123
+
124
+ - Type: Required
125
+ - Description: Client Secret of the GitHub OAuth application.
126
+ - Default: `-`
127
+ - Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
128
+
129
+ ### Microsoft
130
+
131
+ #### `AUTH_MICROSOFT_ID`
132
+
133
+ - Type: Required
134
+ - Description: Client ID of the Microsoft Entra ID (Azure AD) application. Get it from [Azure Portal](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade).
135
+ - Default: `-`
136
+ - Example: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
137
+
138
+ #### `AUTH_MICROSOFT_SECRET`
139
+
140
+ - Type: Required
141
+ - Description: Client Secret of the Microsoft Entra ID application.
142
+ - Default: `-`
143
+ - Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
144
+
145
+ ### AWS Cognito
146
+
147
+ #### `AUTH_COGNITO_ID`
148
+
149
+ - Type: Required
150
+ - Description: Client ID of the AWS Cognito User Pool App Client. Get it from [AWS Cognito Console](https://console.aws.amazon.com/cognito).
151
+ - Default: `-`
152
+ - Example: `xxxxxxxxxxxxxxxxxxxxx`
153
+
154
+ #### `AUTH_COGNITO_SECRET`
155
+
156
+ - Type: Required
157
+ - Description: Client Secret of the AWS Cognito App Client.
158
+ - Default: `-`
159
+ - Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
160
+
161
+ #### `AUTH_COGNITO_ISSUER`
162
+
163
+ - Type: Required
164
+ - Description: The Cognito User Pool issuer URL. Format: `https://cognito-idp.{region}.amazonaws.com/{userPoolId}`
165
+ - Default: `-`
166
+ - Example: `https://cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxxx`
167
+
168
+ ### Feishu
169
+
170
+ #### `AUTH_FEISHU_APP_ID`
171
+
172
+ - Type: Required
173
+ - Description: App ID of the Feishu application. Get it from [Feishu Open Platform](https://open.feishu.cn/app).
174
+ - Default: `-`
175
+ - Example: `cli_xxxxxxxxxxxxxxxx`
176
+
177
+ #### `AUTH_FEISHU_APP_SECRET`
178
+
179
+ - Type: Required
180
+ - Description: App Secret of the Feishu application.
181
+ - Default: `-`
182
+ - Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
183
+
184
+ ### WeChat
185
+
186
+ #### `AUTH_WECHAT_ID`
187
+
188
+ - Type: Required
189
+ - Description: App ID of the WeChat Open Platform application. Get it from [WeChat Open Platform](https://open.weixin.qq.com/).
190
+ - Default: `-`
191
+ - Example: `wxxxxxxxxxxxxxxxxxxx`
192
+
193
+ #### `AUTH_WECHAT_SECRET`
194
+
195
+ - Type: Required
196
+ - Description: App Secret of the WeChat application.
197
+ - Default: `-`
198
+ - Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
199
+
200
+ <Callout type={'info'}>
201
+ For other OIDC-based providers (Auth0, Authelia, Authentik, Casdoor, Cloudflare Zero Trust, Keycloak, Logto, Okta, ZITADEL, Generic OIDC), the environment variables follow the same pattern as Next Auth. See the [Next Auth section](#next-auth) below for details.
202
+ </Callout>
203
+
18
204
  ## Next Auth
19
205
 
20
206
  ### General Settings