@lobehub/lobehub 2.0.0-next.339 → 2.0.0-next.340
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.
- package/CHANGELOG.md +25 -0
- package/changelog/v1.json +9 -0
- package/docs/self-hosting/advanced/auth/clerk-to-betterauth.mdx +366 -0
- package/docs/self-hosting/advanced/auth/clerk-to-betterauth.zh-CN.mdx +360 -0
- package/docs/self-hosting/advanced/auth/legacy.mdx +4 -0
- package/docs/self-hosting/advanced/auth/legacy.zh-CN.mdx +4 -0
- package/docs/self-hosting/advanced/auth.mdx +55 -30
- package/docs/self-hosting/advanced/auth.zh-CN.mdx +55 -30
- package/locales/ar/auth.json +1 -1
- package/locales/ar/desktop-onboarding.json +1 -0
- package/locales/ar/metadata.json +2 -2
- package/locales/ar/models.json +23 -5
- package/locales/ar/providers.json +0 -1
- package/locales/ar/setting.json +19 -0
- package/locales/bg-BG/auth.json +1 -1
- package/locales/bg-BG/desktop-onboarding.json +1 -0
- package/locales/bg-BG/metadata.json +2 -2
- package/locales/bg-BG/models.json +5 -5
- package/locales/bg-BG/providers.json +0 -1
- package/locales/bg-BG/setting.json +19 -0
- package/locales/de-DE/auth.json +1 -1
- package/locales/de-DE/desktop-onboarding.json +1 -0
- package/locales/de-DE/metadata.json +2 -2
- package/locales/de-DE/models.json +31 -10
- package/locales/de-DE/providers.json +0 -1
- package/locales/de-DE/setting.json +19 -0
- package/locales/en-US/auth.json +3 -2
- package/locales/en-US/metadata.json +2 -2
- package/locales/en-US/models.json +10 -11
- package/locales/en-US/providers.json +0 -1
- package/locales/es-ES/auth.json +1 -1
- package/locales/es-ES/desktop-onboarding.json +1 -0
- package/locales/es-ES/metadata.json +2 -2
- package/locales/es-ES/models.json +32 -5
- package/locales/es-ES/providers.json +0 -1
- package/locales/es-ES/setting.json +19 -0
- package/locales/fa-IR/auth.json +1 -1
- package/locales/fa-IR/desktop-onboarding.json +1 -0
- package/locales/fa-IR/metadata.json +2 -2
- package/locales/fa-IR/models.json +35 -5
- package/locales/fa-IR/providers.json +0 -1
- package/locales/fa-IR/setting.json +19 -0
- package/locales/fr-FR/auth.json +1 -1
- package/locales/fr-FR/desktop-onboarding.json +1 -0
- package/locales/fr-FR/metadata.json +2 -2
- package/locales/fr-FR/models.json +33 -5
- package/locales/fr-FR/providers.json +0 -1
- package/locales/fr-FR/setting.json +19 -0
- package/locales/it-IT/auth.json +1 -1
- package/locales/it-IT/desktop-onboarding.json +1 -0
- package/locales/it-IT/metadata.json +2 -2
- package/locales/it-IT/models.json +3 -8
- package/locales/it-IT/providers.json +0 -1
- package/locales/it-IT/setting.json +19 -0
- package/locales/ja-JP/auth.json +1 -1
- package/locales/ja-JP/desktop-onboarding.json +1 -0
- package/locales/ja-JP/metadata.json +2 -2
- package/locales/ja-JP/models.json +32 -5
- package/locales/ja-JP/providers.json +0 -1
- package/locales/ja-JP/setting.json +19 -0
- package/locales/ko-KR/auth.json +1 -1
- package/locales/ko-KR/desktop-onboarding.json +1 -0
- package/locales/ko-KR/metadata.json +2 -2
- package/locales/ko-KR/models.json +3 -8
- package/locales/ko-KR/providers.json +0 -1
- package/locales/ko-KR/setting.json +19 -0
- package/locales/nl-NL/auth.json +1 -1
- package/locales/nl-NL/desktop-onboarding.json +1 -0
- package/locales/nl-NL/metadata.json +2 -2
- package/locales/nl-NL/models.json +45 -4
- package/locales/nl-NL/providers.json +0 -1
- package/locales/nl-NL/setting.json +19 -0
- package/locales/pl-PL/auth.json +1 -1
- package/locales/pl-PL/desktop-onboarding.json +1 -0
- package/locales/pl-PL/metadata.json +2 -2
- package/locales/pl-PL/models.json +37 -5
- package/locales/pl-PL/providers.json +0 -1
- package/locales/pl-PL/setting.json +19 -0
- package/locales/pt-BR/auth.json +1 -1
- package/locales/pt-BR/desktop-onboarding.json +1 -0
- package/locales/pt-BR/metadata.json +2 -2
- package/locales/pt-BR/models.json +28 -4
- package/locales/pt-BR/providers.json +0 -1
- package/locales/pt-BR/setting.json +19 -0
- package/locales/ru-RU/auth.json +1 -1
- package/locales/ru-RU/desktop-onboarding.json +1 -0
- package/locales/ru-RU/metadata.json +2 -2
- package/locales/ru-RU/models.json +3 -8
- package/locales/ru-RU/providers.json +0 -1
- package/locales/ru-RU/setting.json +19 -0
- package/locales/tr-TR/auth.json +1 -1
- package/locales/tr-TR/desktop-onboarding.json +1 -0
- package/locales/tr-TR/metadata.json +2 -2
- package/locales/tr-TR/models.json +26 -7
- package/locales/tr-TR/providers.json +0 -1
- package/locales/tr-TR/setting.json +19 -0
- package/locales/vi-VN/auth.json +1 -1
- package/locales/vi-VN/desktop-onboarding.json +1 -0
- package/locales/vi-VN/metadata.json +2 -2
- package/locales/vi-VN/models.json +3 -5
- package/locales/vi-VN/providers.json +0 -1
- package/locales/vi-VN/setting.json +19 -0
- package/locales/zh-CN/auth.json +3 -3
- package/locales/zh-CN/metadata.json +2 -2
- package/locales/zh-CN/models.json +46 -6
- package/locales/zh-CN/providers.json +0 -1
- package/locales/zh-TW/auth.json +1 -1
- package/locales/zh-TW/desktop-onboarding.json +1 -0
- package/locales/zh-TW/metadata.json +2 -2
- package/locales/zh-TW/models.json +39 -6
- package/locales/zh-TW/providers.json +0 -1
- package/locales/zh-TW/setting.json +19 -0
- package/package.json +1 -1
- package/packages/const/src/url.ts +1 -1
- package/public/og/agent-og.webp +0 -0
- package/public/og/mcp-og.webp +0 -0
- package/public/og/og.webp +0 -0
- package/scripts/clerk-to-betterauth/__tests__/parseCsvLine.test.ts +21 -0
- package/scripts/clerk-to-betterauth/_internal/config.ts +55 -0
- package/scripts/clerk-to-betterauth/_internal/db.ts +32 -0
- package/scripts/clerk-to-betterauth/_internal/env.ts +6 -0
- package/scripts/clerk-to-betterauth/_internal/load-data-from-files.ts +74 -0
- package/scripts/clerk-to-betterauth/_internal/types.ts +45 -0
- package/scripts/clerk-to-betterauth/_internal/utils.ts +36 -0
- package/scripts/clerk-to-betterauth/export-clerk-users-with-api.ts +211 -0
- package/scripts/clerk-to-betterauth/index.ts +314 -0
- package/scripts/clerk-to-betterauth/prod/put_clerk_exported_users_csv_here.txt +0 -0
- package/scripts/clerk-to-betterauth/test/put_clerk_exported_users_csv_here.txt +0 -0
- package/scripts/clerk-to-betterauth/verify.ts +275 -0
- package/src/app/[variants]/(auth)/signin/SignInEmailStep.tsx +30 -2
- package/src/app/[variants]/(auth)/signin/SignInPasswordStep.tsx +1 -1
- package/src/app/[variants]/(auth)/signin/page.tsx +3 -0
- package/src/app/[variants]/(auth)/signin/useSignIn.ts +6 -2
- package/src/app/[variants]/(main)/home/features/RecentResource/Item.tsx +2 -2
- package/src/app/[variants]/(main)/home/features/index.tsx +1 -2
- package/src/app/[variants]/(main)/settings/provider/features/ProviderConfig/index.tsx +0 -2
- package/src/app/[variants]/(main)/settings/skill/features/Actions.tsx +8 -7
- package/src/app/[variants]/(main)/settings/skill/features/McpSkillItem.tsx +9 -11
- package/src/app/manifest.ts +4 -4
- package/src/features/AuthCard/index.tsx +1 -1
- package/src/features/SkillStore/CommunityList/Item.tsx +3 -2
- package/src/features/SkillStore/Search/index.tsx +0 -1
- package/src/locales/default/auth.ts +3 -2
- package/src/locales/default/metadata.ts +2 -2
- package/src/server/ld.ts +4 -3
- package/src/styles/global.ts +0 -6
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/apple.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/apple.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/auth0.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/auth0.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/authelia.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/authelia.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/authentik.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/authentik.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/casdoor.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/casdoor.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/cloudflare-zero-trust.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/cloudflare-zero-trust.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/cognito.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/cognito.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/feishu.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/feishu.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/generic-oidc.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/generic-oidc.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/github.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/github.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/google.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/google.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/keycloak.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/keycloak.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/logto.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/logto.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/microsoft.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/microsoft.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/okta.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/okta.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/wechat.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/wechat.zh-CN.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/zitadel.mdx +0 -0
- /package/docs/self-hosting/advanced/auth/{better-auth → providers}/zitadel.zh-CN.mdx +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## [Version 2.0.0-next.340](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.339...v2.0.0-next.340)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2026-01-22**</sup>
|
|
8
|
+
|
|
9
|
+
#### 💄 Styles
|
|
10
|
+
|
|
11
|
+
- **misc**: Update og.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Styles
|
|
19
|
+
|
|
20
|
+
- **misc**: Update og, closes [#11709](https://github.com/lobehub/lobe-chat/issues/11709) ([01cf4e4](https://github.com/lobehub/lobe-chat/commit/01cf4e4))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 2.0.0-next.339](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.338...v2.0.0-next.339)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2026-01-22**</sup>
|
package/changelog/v1.json
CHANGED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Migrating from Clerk to Better Auth
|
|
3
|
+
description: >-
|
|
4
|
+
Guide for migrating your LobeChat deployment from Clerk authentication to
|
|
5
|
+
Better Auth, including simple and full migration options.
|
|
6
|
+
tags:
|
|
7
|
+
- Authentication Service
|
|
8
|
+
- Better Auth
|
|
9
|
+
- Clerk
|
|
10
|
+
- Migration
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Migrating from Clerk to Better Auth
|
|
14
|
+
|
|
15
|
+
This guide helps you migrate your existing Clerk-based LobeChat deployment to Better Auth.
|
|
16
|
+
|
|
17
|
+
<Callout type={'info'}>
|
|
18
|
+
Better Auth is the recommended authentication solution for LobeChat. It offers simpler configuration, more SSO providers, and better self-hosting support.
|
|
19
|
+
</Callout>
|
|
20
|
+
|
|
21
|
+
<Callout type={'error'}>
|
|
22
|
+
**Important Notice**:
|
|
23
|
+
|
|
24
|
+
- **Always backup your database first!** For Neon users, create a backup via [Fork Branch](https://neon.tech/docs/manage/branches#create-a-branch)
|
|
25
|
+
- LobeChat is not responsible for any data loss or issues that may occur during the migration process
|
|
26
|
+
- 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
|
|
28
|
+
</Callout>
|
|
29
|
+
|
|
30
|
+
## Choose Your Migration Path
|
|
31
|
+
|
|
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 |
|
|
36
|
+
|
|
37
|
+
## Simple Migration
|
|
38
|
+
|
|
39
|
+
For small self-hosted deployments, the simplest approach is to let users reset their passwords.
|
|
40
|
+
|
|
41
|
+
<Callout type={'warning'}>
|
|
42
|
+
**Limitation**: This method loses SSO connection data. Use [Full Migration](#full-migration) to preserve SSO connections.
|
|
43
|
+
|
|
44
|
+
**Example scenario**: If your previous account had two SSO accounts linked:
|
|
45
|
+
|
|
46
|
+
- Primary email (Google): `mail1@google.com`
|
|
47
|
+
- Secondary email (Microsoft): `mail2@outlook.com`
|
|
48
|
+
|
|
49
|
+
After migrating and resetting password with `mail1@google.com`, logging in with `mail2@outlook.com` will create a **new user** instead of linking to your existing account.
|
|
50
|
+
</Callout>
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
### Steps
|
|
55
|
+
|
|
56
|
+
1. **Configure Email Service**
|
|
57
|
+
|
|
58
|
+
Set up email service for password reset functionality. See [Email Service Configuration](/docs/self-hosting/advanced/auth#email-service-configuration).
|
|
59
|
+
|
|
60
|
+
2. **Update Environment Variables**
|
|
61
|
+
|
|
62
|
+
Remove Clerk variables and add Better Auth variables:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Remove these
|
|
66
|
+
# NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=xxx
|
|
67
|
+
# CLERK_SECRET_KEY=xxx
|
|
68
|
+
|
|
69
|
+
# Add these
|
|
70
|
+
AUTH_SECRET=your-secret-key # openssl rand -base64 32
|
|
71
|
+
|
|
72
|
+
# Optional: Enable Google SSO (example)
|
|
73
|
+
AUTH_SSO_PROVIDERS=google
|
|
74
|
+
AUTH_GOOGLE_ID=your-google-client-id
|
|
75
|
+
AUTH_GOOGLE_SECRET=your-google-client-secret
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
<Callout type={'tip'}>
|
|
79
|
+
See [Authentication Service Configuration](/docs/self-hosting/advanced/auth) for complete environment variables and SSO provider setup.
|
|
80
|
+
</Callout>
|
|
81
|
+
|
|
82
|
+
3. **Redeploy LobeChat**
|
|
83
|
+
|
|
84
|
+
Deploy the new version with Better Auth enabled.
|
|
85
|
+
|
|
86
|
+
4. **Notify Users**
|
|
87
|
+
|
|
88
|
+
Inform users to follow these steps to log in (chat history and settings will be preserved):
|
|
89
|
+
|
|
90
|
+
1. Visit the login page (e.g., `https://your-domain.com/signin`)
|
|
91
|
+
2. Enter their previous email address and press Enter
|
|
92
|
+
|
|
93
|
+
If Magic Link is enabled: The system will automatically send a login link email.
|
|
94
|
+
Users can click the link to log in directly.
|
|
95
|
+
|
|
96
|
+
If Magic Link is not enabled: The page will display a hint message. Users can either:
|
|
97
|
+
|
|
98
|
+
- Log in using their previously linked social account (e.g., Google, GitHub)
|
|
99
|
+
- Click "Set Password" to receive an email and set a new password
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
3. (Optional) After logging in, users can manage their account in the Profile page:
|
|
104
|
+
- Linked Accounts: Link additional social accounts
|
|
105
|
+
- Password: Set or update password at any time
|
|
106
|
+
|
|
107
|
+
<Callout type={'tip'}>
|
|
108
|
+
This method is quick and requires minimal setup.
|
|
109
|
+
Users can log in via Magic Link, social accounts, or by setting a new password.
|
|
110
|
+
All data remains intact.
|
|
111
|
+
Users can manage their password and linked accounts anytime in the [Profile page](/settings/profile).
|
|
112
|
+
</Callout>
|
|
113
|
+
|
|
114
|
+
## Full Migration
|
|
115
|
+
|
|
116
|
+
For larger deployments or when you need to preserve user passwords and SSO connections, use the migration scripts.
|
|
117
|
+
|
|
118
|
+
<Callout type={'error'}>
|
|
119
|
+
**Important Notice**:
|
|
120
|
+
|
|
121
|
+
- Migration scripts must be **run locally after cloning the repository**, not in the deployment environment
|
|
122
|
+
- Due to the high-risk nature of user data migration, **we do not provide automatic migration during deployment**
|
|
123
|
+
- Always verify in a test environment before operating on production database
|
|
124
|
+
</Callout>
|
|
125
|
+
|
|
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
|
+
|
|
134
|
+
### Prerequisites
|
|
135
|
+
|
|
136
|
+
**Environment Requirements:**
|
|
137
|
+
|
|
138
|
+
- Node.js 18+
|
|
139
|
+
- Git (for cloning the repository)
|
|
140
|
+
- pnpm (for installing dependencies)
|
|
141
|
+
|
|
142
|
+
**Preparation:**
|
|
143
|
+
|
|
144
|
+
1. Clone the LobeChat repository and install dependencies:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
git clone https://github.com/lobehub/lobe-chat.git
|
|
148
|
+
cd lobe-chat
|
|
149
|
+
pnpm install
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
2. Prepare the following information:
|
|
153
|
+
- Access to Clerk Dashboard (for CSV export)
|
|
154
|
+
- Clerk API Secret Key (for API export)
|
|
155
|
+
- Database connection string
|
|
156
|
+
|
|
157
|
+
3. Ensure database schema is up to date
|
|
158
|
+
|
|
159
|
+
<Callout type={'info'}>
|
|
160
|
+
If you've been on an older version (e.g., 1.x) for a while, your database schema may be outdated. Run this in the cloned repository:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
DATABASE_URL=your-database-url pnpm db:migrate
|
|
164
|
+
```
|
|
165
|
+
</Callout>
|
|
166
|
+
|
|
167
|
+
### Step 1: Configure Migration Script Environment Variables
|
|
168
|
+
|
|
169
|
+
Create a `.env` file in the project root (the script will automatically load it) with all environment variables:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# ============================================
|
|
173
|
+
# Migration mode: test or prod
|
|
174
|
+
# Recommended: Start with test mode to verify on a test database,
|
|
175
|
+
# then switch to prod after confirming everything works
|
|
176
|
+
# ============================================
|
|
177
|
+
CLERK_TO_BETTERAUTH_MODE=test
|
|
178
|
+
|
|
179
|
+
# ============================================
|
|
180
|
+
# Database connection (uses corresponding variable based on mode)
|
|
181
|
+
# TEST_ prefix for test environment, PROD_ prefix for production
|
|
182
|
+
# ============================================
|
|
183
|
+
TEST_CLERK_TO_BETTERAUTH_DATABASE_URL=postgresql://user:pass@test-host:5432/testdb
|
|
184
|
+
PROD_CLERK_TO_BETTERAUTH_DATABASE_URL=postgresql://user:pass@prod-host:5432/proddb
|
|
185
|
+
|
|
186
|
+
# ============================================
|
|
187
|
+
# Clerk API keys (for exporting user data via API)
|
|
188
|
+
# Get from Clerk Dashboard: Configure → Developers → API Keys
|
|
189
|
+
# ============================================
|
|
190
|
+
TEST_CLERK_TO_BETTERAUTH_CLERK_SECRET_KEY=sk_test_xxx
|
|
191
|
+
PROD_CLERK_TO_BETTERAUTH_CLERK_SECRET_KEY=sk_live_xxx
|
|
192
|
+
|
|
193
|
+
# ============================================
|
|
194
|
+
# Database driver (optional)
|
|
195
|
+
# neon: Neon serverless driver (default)
|
|
196
|
+
# node: node-postgres driver
|
|
197
|
+
# ============================================
|
|
198
|
+
CLERK_TO_BETTERAUTH_DATABASE_DRIVER=neon
|
|
199
|
+
|
|
200
|
+
# ============================================
|
|
201
|
+
# Dry Run mode (optional)
|
|
202
|
+
# Set to 1 to only print logs without modifying the database
|
|
203
|
+
# Recommended: Enable for first run, disable after verification
|
|
204
|
+
# ============================================
|
|
205
|
+
CLERK_TO_BETTERAUTH_DRY_RUN=1
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Step 2: Export Clerk Data
|
|
209
|
+
|
|
210
|
+
#### Stop New User Registration
|
|
211
|
+
|
|
212
|
+
Before exporting data, disable new user registration to ensure data consistency during migration:
|
|
213
|
+
|
|
214
|
+
1. Go to [Clerk Dashboard](https://dashboard.clerk.com) → Configure → Restrictions
|
|
215
|
+
2. Enable "Restricted" mode
|
|
216
|
+
|
|
217
|
+
#### Export CSV from Clerk Dashboard
|
|
218
|
+
|
|
219
|
+
1. Go to [Clerk Dashboard](https://dashboard.clerk.com) → Configure → Settings → User exports
|
|
220
|
+
2. Click "Export users" to download the CSV file
|
|
221
|
+
3. Save it to `scripts/clerk-to-betterauth/test/clerk_exported_users.csv`
|
|
222
|
+
|
|
223
|
+
See [Clerk documentation](https://clerk.com/docs/guides/development/migrating/overview#export-your-users-data-from-the-clerk-dashboard) for details.
|
|
224
|
+
|
|
225
|
+

|
|
226
|
+
|
|
227
|
+
#### Export JSON via API
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Run export script (automatically selects key and output path based on CLERK_TO_BETTERAUTH_MODE)
|
|
231
|
+
npx tsx scripts/clerk-to-betterauth/export-clerk-users-with-api.ts
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
This automatically creates `scripts/clerk-to-betterauth/test/clerk_users.json` with additional user data.
|
|
235
|
+
|
|
236
|
+
### Step 3: Dry-Run Verification (Test Environment)
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# Run migration (CLERK_TO_BETTERAUTH_DRY_RUN=1, only logs without modifying database)
|
|
240
|
+
npx tsx scripts/clerk-to-betterauth/index.ts
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Review the output logs, confirm no issues, then proceed to the next step.
|
|
244
|
+
|
|
245
|
+
### Step 4: Execute Migration and Verify (Test Environment)
|
|
246
|
+
|
|
247
|
+
Update `.env` to set `CLERK_TO_BETTERAUTH_DRY_RUN` to `0`, then execute:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Execute migration
|
|
251
|
+
npx tsx scripts/clerk-to-betterauth/index.ts
|
|
252
|
+
|
|
253
|
+
# Verify the migration
|
|
254
|
+
npx tsx scripts/clerk-to-betterauth/verify.ts
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
After verifying the test environment migration is successful, proceed to the next step.
|
|
258
|
+
|
|
259
|
+
### Step 5: Dry-Run Verification (Production Environment)
|
|
260
|
+
|
|
261
|
+
1. Copy the CSV file to prod directory: `scripts/clerk-to-betterauth/prod/clerk_exported_users.csv`
|
|
262
|
+
2. Update `.env` file:
|
|
263
|
+
- Change `CLERK_TO_BETTERAUTH_MODE` to `prod`
|
|
264
|
+
- Change `CLERK_TO_BETTERAUTH_DRY_RUN` back to `1`
|
|
265
|
+
3. Run the scripts:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# Export production user data
|
|
269
|
+
npx tsx scripts/clerk-to-betterauth/export-clerk-users-with-api.ts
|
|
270
|
+
|
|
271
|
+
# Run migration (dry-run mode to verify)
|
|
272
|
+
npx tsx scripts/clerk-to-betterauth/index.ts
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Review the output logs, confirm no issues, then proceed to the next step.
|
|
276
|
+
|
|
277
|
+
### Step 6: Execute Migration and Verify (Production Environment)
|
|
278
|
+
|
|
279
|
+
Update `.env` to set `CLERK_TO_BETTERAUTH_DRY_RUN` to `0`, then execute:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Execute migration
|
|
283
|
+
npx tsx scripts/clerk-to-betterauth/index.ts
|
|
284
|
+
|
|
285
|
+
# Verify the migration
|
|
286
|
+
npx tsx scripts/clerk-to-betterauth/verify.ts
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Step 7: Configure Better Auth and Redeploy
|
|
290
|
+
|
|
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**
|
|
319
|
+
|
|
320
|
+
<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.
|
|
322
|
+
</Callout>
|
|
323
|
+
|
|
324
|
+
## What Gets Migrated
|
|
325
|
+
|
|
326
|
+
| Data | Simple Migration | Full Migration |
|
|
327
|
+
| -------------------------------------- | ---------------------- | -------------- |
|
|
328
|
+
| User accounts | ✅ (via password reset) | ✅ |
|
|
329
|
+
| Password hashes | ❌ | ✅ |
|
|
330
|
+
| SSO connections (Google, GitHub, etc.) | ❌ | ✅ |
|
|
331
|
+
| Two-factor authentication | ❌ | ✅ |
|
|
332
|
+
| Chat history | ✅ | ✅ |
|
|
333
|
+
| User settings | ✅ | ✅ |
|
|
334
|
+
|
|
335
|
+
## Troubleshooting
|
|
336
|
+
|
|
337
|
+
### Users can't log in after migration
|
|
338
|
+
|
|
339
|
+
- Ensure email service is configured for password reset
|
|
340
|
+
- Check that `AUTH_SECRET` is set correctly
|
|
341
|
+
- Verify database connection is working
|
|
342
|
+
|
|
343
|
+
### SSO users can't connect
|
|
344
|
+
|
|
345
|
+
- For simple migration: Users need to link their SSO accounts again after resetting password
|
|
346
|
+
- For full migration: Verify the SSO provider is configured in `AUTH_SSO_PROVIDERS`
|
|
347
|
+
|
|
348
|
+
### Migration script fails
|
|
349
|
+
|
|
350
|
+
- Check database connection string
|
|
351
|
+
- Ensure CSV and JSON files are in the correct location
|
|
352
|
+
- Review script logs for specific errors
|
|
353
|
+
|
|
354
|
+
### column "xxx" of relation "users" does not exist
|
|
355
|
+
|
|
356
|
+
This error occurs because the database schema is outdated. Run `pnpm db:migrate` to update the database structure before running the migration script.
|
|
357
|
+
|
|
358
|
+
## Related Reading
|
|
359
|
+
|
|
360
|
+
<Cards>
|
|
361
|
+
<Card href={'/docs/self-hosting/advanced/auth'} title={'Authentication Service Configuration'} />
|
|
362
|
+
|
|
363
|
+
<Card href={'/docs/self-hosting/environment-variables/auth'} title={'Auth Environment Variables'} />
|
|
364
|
+
|
|
365
|
+
<Card href={'/docs/self-hosting/advanced/auth/legacy'} title={'Legacy Authentication (NextAuth & Clerk)'} />
|
|
366
|
+
</Cards>
|