Skip to content

Commit 395595a

Browse files
authored
✨ feat: remove Clerk authentication code (#11711)
1 parent e999851 commit 395595a

File tree

127 files changed

+520
-13362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+520
-13362
lines changed

.cursor/rules/i18n.mdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ t('common:save')
7979

8080
## Available Namespaces
8181

82-
auth, authError, changelog, chat, clerk, color, **common**, components, discover, editor, electron, error, file, home, hotkey, image, knowledgeBase, labs, marketAuth, memory, metadata, migration, modelProvider, models, oauth, onboarding, plugin, portal, providers, ragEval, **setting**, subscription, thread, tool, topic, welcome
82+
auth, authError, changelog, chat, color, **common**, components, discover, editor, electron, error, file, home, hotkey, image, knowledgeBase, labs, marketAuth, memory, metadata, migration, modelProvider, models, oauth, onboarding, plugin, portal, providers, ragEval, **setting**, subscription, thread, tool, topic, welcome
8383

8484
**Most used:** `common` (shared UI), `chat` (chat features), `setting` (settings)

.env.example

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,6 @@ OPENAI_API_KEY=sk-xxxxxxxxx
277277
# ########### Auth Service ##############
278278
# #######################################
279279

280-
281-
# Clerk related configurations
282-
283-
# Clerk public key and secret key
284-
# NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxx
285-
# CLERK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxx
286-
287-
# you need to config the clerk webhook secret key if you want to use the clerk with database
288-
# CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx
289-
290-
# Clear allow origin https://clerk.com/docs/guides/dashboard/dns-domains/satellite-domains
291-
# Authentication across different domains , use,to splite different origin
292-
# NEXT_PUBLIC_CLERK_AUTH_ALLOW_ORIGINS='https://market.lobehub.com,https://lobehub.com'
293-
294280
# NextAuth related configurations
295281
# NEXT_PUBLIC_ENABLE_NEXT_AUTH=1
296282
# NEXT_AUTH_SECRET=

.eslintrc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ config.overrides = [
3838
'mdx/code-blocks': false,
3939
},
4040
},
41-
4241
{
4342
files: ['src/store/image/**/*', 'src/types/generation/**/*'],
4443
rules: {
@@ -48,6 +47,14 @@ config.overrides = [
4847
'typescript-sort-keys/string-enum': 0,
4948
},
5049
},
50+
// CLI scripts legitimately use process.exit() and async IIFE patterns
51+
{
52+
files: ['scripts/**/*'],
53+
rules: {
54+
'unicorn/no-process-exit': 0,
55+
'unicorn/prefer-top-level-await': 0,
56+
},
57+
},
5158
];
5259

5360
module.exports = config;

.npmrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ public-hoist-pattern[]=*semantic-release*
1616
public-hoist-pattern[]=*stylelint*
1717

1818
public-hoist-pattern[]=@auth/core
19-
public-hoist-pattern[]=@clerk/backend
20-
public-hoist-pattern[]=@clerk/types
2119
public-hoist-pattern[]=pdfjs-dist

Dockerfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ FROM base AS builder
3232

3333
ARG USE_CN_MIRROR
3434
ARG NEXT_PUBLIC_BASE_PATH
35-
ARG NEXT_PUBLIC_ENABLE_BETTER_AUTH
3635
ARG NEXT_PUBLIC_ENABLE_NEXT_AUTH
37-
ARG NEXT_PUBLIC_ENABLE_CLERK_AUTH
38-
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
3936
ARG NEXT_PUBLIC_SENTRY_DSN
4037
ARG NEXT_PUBLIC_ANALYTICS_POSTHOG
4138
ARG NEXT_PUBLIC_POSTHOG_HOST
@@ -48,11 +45,7 @@ ARG FEATURE_FLAGS
4845
ENV NEXT_PUBLIC_BASE_PATH="${NEXT_PUBLIC_BASE_PATH}" \
4946
FEATURE_FLAGS="${FEATURE_FLAGS}"
5047

51-
ENV NEXT_PUBLIC_ENABLE_BETTER_AUTH="${NEXT_PUBLIC_ENABLE_BETTER_AUTH:-0}" \
52-
NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
53-
NEXT_PUBLIC_ENABLE_CLERK_AUTH="${NEXT_PUBLIC_ENABLE_CLERK_AUTH:-0}" \
54-
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}" \
55-
CLERK_WEBHOOK_SECRET="whsec_xxx" \
48+
ENV NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-0}" \
5649
APP_URL="http://app.com" \
5750
DATABASE_DRIVER="node" \
5851
DATABASE_URL="postgres://postgres:password@localhost:5432/postgres" \
@@ -142,8 +135,9 @@ COPY --from=builder /deps/node_modules/.pnpm /app/node_modules/.pnpm
142135
COPY --from=builder /deps/node_modules/pg /app/node_modules/pg
143136
COPY --from=builder /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm
144137

145-
# Copy server launcher
138+
# Copy server launcher and shared scripts
146139
COPY --from=builder /app/scripts/serverLauncher/startServer.js /app/startServer.js
140+
COPY --from=builder /app/scripts/_shared /app/scripts/_shared
147141

148142
RUN <<'EOF'
149143
set -e
@@ -191,10 +185,6 @@ ENV KEY_VAULTS_SECRET="" \
191185
ENV AUTH_SECRET="" \
192186
AUTH_SSO_PROVIDERS=""
193187

194-
# Clerk
195-
ENV CLERK_SECRET_KEY="" \
196-
CLERK_WEBHOOK_SECRET=""
197-
198188
# S3
199189
ENV NEXT_PUBLIC_S3_DOMAIN="" \
200190
S3_PUBLIC_DOMAIN="" \

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,11 @@ Regardless of which database you choose, LobeChat can provide you with an excell
422422

423423
### [Support Multi-User Management][docs-feat-auth]
424424

425-
LobeChat supports multi-user management and provides two main user authentication and management solutions to meet different needs:
425+
LobeChat supports multi-user management and provides flexible user authentication solutions:
426426

427-
- **next-auth**: LobeChat integrates `next-auth`, a flexible and powerful identity verification library that supports multiple authentication methods, including OAuth, email login, credential login, etc. With `next-auth`, you can easily implement user registration, login, session management, social login, and other functions to ensure the security and privacy of user data.
427+
- **Better Auth**: LobeChat integrates `Better Auth`, a modern and flexible authentication library that supports multiple authentication methods, including OAuth, email login, credential login, magic link, and more. With `Better Auth`, you can easily implement user registration, login, session management, social login, multi-factor authentication (MFA), and other functions to ensure the security and privacy of user data.
428428

429-
- [**Clerk**](https://go.clerk.com/exgqLG0): For users who need more advanced user management features, LobeChat also supports `Clerk`, a modern user management platform. `Clerk` provides richer functions, such as multi-factor authentication (MFA), user profile management, login activity monitoring, etc. With `Clerk`, you can get higher security and flexibility, and easily cope with complex user management needs.
430-
431-
Regardless of which user management solution you choose, LobeChat can provide you with an excellent user experience and powerful functional support.
429+
- **next-auth**: LobeChat also supports `next-auth`, a widely-used identity verification library with extensive OAuth provider support and flexible session management options.
432430

433431
<div align="right">
434432

README.zh-CN.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,11 @@ LobeChat 支持同时使用服务端数据库和本地数据库。根据您的
411411

412412
### [支持多用户管理][docs-feat-auth]
413413

414-
LobeChat 支持多用户管理,提供了两种主要的用户认证和管理方案,以满足不同需求
414+
LobeChat 支持多用户管理,提供了灵活的用户认证方案
415415

416-
- **next-auth**:LobeChat 集成了 `next-auth`,一个灵活且强大的身份验证库,支持多种身份验证方式,包括 OAuth、邮件登录、凭证登录等。通过 `next-auth`,您可以轻松实现用户的注册、登录、会话管理以及社交登录等功能,确保用户数据的安全性和隐私性。
416+
- **Better Auth**:LobeChat 集成了 `Better Auth`,一个现代化且灵活的身份验证库,支持多种身份验证方式,包括 OAuth、邮件登录、凭证登录、魔法链接等。通过 `Better Auth`,您可以轻松实现用户的注册、登录、会话管理、社交登录、多因素认证 (MFA) 等功能,确保用户数据的安全性和隐私性。
417417

418-
- [**Clerk**](https://go.clerk.com/exgqLG0):对于需要更高级用户管理功能的用户,LobeChat 还支持 `Clerk`,一个现代化的用户管理平台。`Clerk` 提供了更丰富的功能,如多因素认证 (MFA)、白名单、用户管理、登录活动监控等。通过 `Clerk`,您可以获得更高的安全性和灵活性,轻松应对生产级的用户管理需求。
419-
420-
您可以根据自己的需求,选择合适的用户管理方案。
418+
- **next-auth**:LobeChat 还支持 `next-auth`,一个广泛使用的身份验证库,具有丰富的 OAuth 提供商支持和灵活的会话管理选项。
421419

422420
<div align="right">
423421

apps/desktop/.npmrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ public-hoist-pattern[]=*semantic-release*
1717
public-hoist-pattern[]=*stylelint*
1818

1919
public-hoist-pattern[]=@auth/core
20-
public-hoist-pattern[]=@clerk/backend
21-
public-hoist-pattern[]=@clerk/types
2220
public-hoist-pattern[]=pdfjs-dist

docs/self-hosting/advanced/auth/clerk-to-betterauth.mdx

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ This guide helps you migrate your existing Clerk-based LobeChat deployment to Be
2424
- **Always backup your database first!** For Neon users, create a backup via [Fork Branch](https://neon.tech/docs/manage/branches#create-a-branch)
2525
- LobeChat is not responsible for any data loss or issues that may occur during the migration process
2626
- This guide is intended for users with development experience; not recommended for users without technical background
27-
- If you have any questions, feel free to ask in our [Discord](https://discord.com/invite/AYFPHvv2jT) community
27+
- If you have any questions, feel free to ask in our [Discord](https://discord.com/invite/AYFPHvv2jT) community or [GitHub Issue](https://github.com/lobehub/lobe-chat/issues/11707)
2828
</Callout>
2929

3030
## Choose Your Migration Path
3131

32-
| Method | Best For | User Impact | Data Preserved |
33-
| ------------------------------------- | -------------------------------- | --------------------- | ------------------------------ |
34-
| [Simple Migration](#simple-migration) | Small deployments (\< 100 users) | Users reset passwords | Chat history, settings |
35-
| [Full Migration](#full-migration) | Large deployments | Seamless for users | Everything including passwords |
32+
| Method | Best For | User Impact | Data Preserved |
33+
| ------------------------------------- | ------------------------------ | --------------------- | ------------------------------ |
34+
| [Simple Migration](#simple-migration) | Small deployments (≤ 10 users) | Users reset passwords | Chat history, settings |
35+
| [Full Migration](#full-migration) | Large deployments | Seamless for users | Everything including passwords |
3636

3737
## Simple Migration
3838

@@ -41,6 +41,8 @@ For small self-hosted deployments, the simplest approach is to let users reset t
4141
<Callout type={'warning'}>
4242
**Limitation**: This method loses SSO connection data. Use [Full Migration](#full-migration) to preserve SSO connections.
4343

44+
Although SSO connections are lost, users can manually re-link their social accounts from the Profile page after logging in with email and password.
45+
4446
**Example scenario**: If your previous account had two SSO accounts linked:
4547

4648
- Primary email (Google): `mail1@google.com`
@@ -118,19 +120,13 @@ For larger deployments or when you need to preserve user passwords and SSO conne
118120
<Callout type={'error'}>
119121
**Important Notice**:
120122

123+
- **Always backup your database first!** For Neon users, create a backup via [Fork Branch](https://neon.tech/docs/manage/branches#create-a-branch)
121124
- Migration scripts must be **run locally after cloning the repository**, not in the deployment environment
122125
- Due to the high-risk nature of user data migration, **we do not provide automatic migration during deployment**
126+
- Always use dry-run mode first to verify the script runs successfully before executing
123127
- Always verify in a test environment before operating on production database
124128
</Callout>
125129

126-
<Callout type={'warning'}>
127-
**Before Migration**:
128-
129-
- Use a [Neon Fork Branch](https://neon.tech/docs/manage/branches#create-a-branch) to create a test database
130-
- Use Clerk Development environment API keys
131-
- Verify in test mode first, then switch to prod mode after confirming success
132-
</Callout>
133-
134130
### Prerequisites
135131

136132
**Environment Requirements:**
@@ -288,37 +284,10 @@ npx tsx scripts/clerk-to-betterauth/verify.ts
288284

289285
### Step 7: Configure Better Auth and Redeploy
290286

291-
After migration is complete, configure Better Auth environment variables and redeploy:
292-
293-
1. **Remove Clerk environment variables**:
294-
295-
```bash
296-
# Remove these
297-
# NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=xxx
298-
# CLERK_SECRET_KEY=xxx
299-
```
300-
301-
2. **Add Better Auth environment variables**:
302-
303-
```bash
304-
# Required
305-
AUTH_SECRET=your-secret-key # openssl rand -base64 32
306-
307-
# Optional: Configure SSO providers (example)
308-
AUTH_SSO_PROVIDERS=google,github
309-
AUTH_GOOGLE_ID=your-google-client-id
310-
AUTH_GOOGLE_SECRET=your-google-client-secret
311-
AUTH_GITHUB_ID=your-github-client-id
312-
AUTH_GITHUB_SECRET=your-github-client-secret
313-
314-
# Optional: Configure email service (for password reset, email verification, etc.)
315-
# See Authentication Service Configuration documentation for details
316-
```
317-
318-
3. **Redeploy LobeChat**
287+
After migration is complete, follow [Simple Migration - Step 2](#steps) to configure Better Auth environment variables and redeploy.
319288

320289
<Callout type={'tip'}>
321-
For complete Better Auth configuration, see [Authentication Service Configuration](/docs/self-hosting/advanced/auth), including all supported SSO providers and email service configuration.
290+
For complete Better Auth configuration, see [Authentication Service Configuration](/docs/self-hosting/advanced/auth).
322291
</Callout>
323292

324293
## What Gets Migrated

docs/self-hosting/advanced/auth/clerk-to-betterauth.zh-CN.mdx

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ tags:
2222
- **务必先备份数据库**!如使用 Neon,可通过 [Fork 分支](https://neon.tech/docs/manage/branches#create-a-branch) 创建备份
2323
- 迁移过程中可能出现的任何数据丢失或问题,LobeChat 概不负责
2424
- 本指南适合有一定开发背景的用户,不建议无技术经验的用户自行操作
25-
- 如有任何疑问,欢迎到 [Discord](https://discord.com/invite/AYFPHvv2jT) 社区提问
25+
- 如有任何疑问,欢迎到 [Discord](https://discord.com/invite/AYFPHvv2jT) 社区或 [GitHub Issue](https://github.com/lobehub/lobe-chat/issues/11707) 提问
2626
</Callout>
2727

2828
## 选择迁移方式
2929

30-
| 方式 | 适用场景 | 用户影响 | 数据保留 |
31-
| ------------- | --------------- | ------- | -------- |
32-
| [简单迁移](#简单迁移) | 小型部署(\< 100 用户) | 用户需重置密码 | 聊天记录、设置 |
33-
| [完整迁移](#完整迁移) | 大型部署 | 对用户无感知 | 全部数据包括密码 |
30+
| 方式 | 适用场景 | 用户影响 | 数据保留 |
31+
| ------------- | ------------- | ------- | -------- |
32+
| [简单迁移](#简单迁移) | 小型部署(≤ 10 用户) | 用户需重置密码 | 聊天记录、设置 |
33+
| [完整迁移](#完整迁移) | 大型部署 | 对用户无感知 | 全部数据包括密码 |
3434

3535
## 简单迁移
3636

@@ -39,6 +39,8 @@ tags:
3939
<Callout type={'warning'}>
4040
**限制**:此方法会丢失 SSO 连接数据。如需保留 SSO 连接,请使用 [完整迁移](#完整迁移)
4141

42+
虽然 SSO 连接会丢失,但用户可以在使用邮箱密码登录后,通过个人资料页手动重新绑定社交账号。
43+
4244
**示例场景**:假设你之前的账户绑定了两个 SSO 账户:
4345

4446
- 主邮箱(Google):`mail1@google.com`
@@ -113,19 +115,13 @@ tags:
113115
<Callout type={'error'}>
114116
**重要说明**
115117

118+
- **务必先备份数据库**!如使用 Neon,可通过 [Fork 分支](https://neon.tech/docs/manage/branches#create-a-branch) 创建备份
116119
- 迁移脚本需要 **clone 仓库后在本地运行**,不是在部署环境中执行
117120
- 由于迁移涉及用户数据,风险较高,**官方不提供部署时自动迁移功能**
121+
- 请务必先使用 dry-run 模式测试脚本能够顺利运行再正式执行
118122
- 请务必在测试环境验证后再操作生产数据库
119123
</Callout>
120124

121-
<Callout type={'warning'}>
122-
**迁移前准备**
123-
124-
- 使用 [Neon Fork 分支](https://neon.tech/docs/manage/branches#create-a-branch) 创建测试数据库
125-
- 使用 Clerk Development 环境的 API 密钥
126-
- 先在 test 模式下验证,确认成功后再切换到 prod 模式
127-
</Callout>
128-
129125
### 前置条件
130126

131127
**环境要求:**
@@ -282,34 +278,7 @@ npx tsx scripts/clerk-to-betterauth/verify.ts
282278

283279
### 步骤 7:配置 Better Auth 并重新部署
284280

285-
迁移完成后,需要配置 Better Auth 环境变量并重新部署:
286-
287-
1. **移除 Clerk 环境变量**
288-
289-
```bash
290-
# 移除这些
291-
# NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=xxx
292-
# CLERK_SECRET_KEY=xxx
293-
```
294-
295-
2. **添加 Better Auth 环境变量**
296-
297-
```bash
298-
# 必需
299-
AUTH_SECRET=your-secret-key # openssl rand -base64 32
300-
301-
# 可选:配置 SSO 提供商(示例)
302-
AUTH_SSO_PROVIDERS=google,github
303-
AUTH_GOOGLE_ID=your-google-client-id
304-
AUTH_GOOGLE_SECRET=your-google-client-secret
305-
AUTH_GITHUB_ID=your-github-client-id
306-
AUTH_GITHUB_SECRET=your-github-client-secret
307-
308-
# 可选:配置邮件服务(用于密码重置、邮箱验证等)
309-
# 参阅身份验证服务配置文档了解详情
310-
```
311-
312-
3. **重新部署 LobeChat**
281+
迁移完成后,参照 [简单迁移 - 步骤 2](#步骤) 配置 Better Auth 环境变量并重新部署。
313282

314283
<Callout type={'tip'}>
315284
完整的 Better Auth 配置请参阅 [身份验证服务配置](/zh/docs/self-hosting/advanced/auth),包括所有支持的 SSO 提供商和邮件服务配置。

0 commit comments

Comments
 (0)