docs: add how to export user data from clerk

This commit is contained in:
Bereket Engida
2025-05-22 01:40:11 -07:00
parent bf51b7dee5
commit c1a4809b03

View File

@@ -11,7 +11,7 @@ This migration will invalidate all active sessions. This guide doesn't currently
## Before You Begin ## Before You Begin
Before starting the migration process, set up Better Auth in your project. Follow the [installation guide](/docs/installation) to get started. Before starting the migration process, set up Better Auth in your project. Follow the [installation guide](/docs/installation) to get started. And go to
<Steps> <Steps>
<Step> <Step>
@@ -134,8 +134,11 @@ export const auth = betterAuth({
```sh ```sh
npx @better-auth/cli migrate npx @better-auth/cli migrate
``` ```
</Step>
<Step>
### Export Clerk Users
Go to the Clerk dashboard and export the users. Check how to do it [here](https://clerk.com/docs/deployments/exporting-users#export-your-users-data-from-the-clerk-dashboard). It will download a CSV file with the users data. You need to save it as `exported_users.csv` and put it in the root of your project.
</Step>
<Step> <Step>
### Create the migration script ### Create the migration script
@@ -175,7 +178,7 @@ function getCSVData(csv: string) {
}>; }>;
} }
const exportedUserCSV = await Bun.file("exported_users.csv").text(); const exportedUserCSV = await Bun.file("exported_users.csv").text(); // this is the file you downloaded from Clerk // [!code highlight]
async function getClerkUsers(totalUsers: number) { async function getClerkUsers(totalUsers: number) {
@@ -358,10 +361,7 @@ migrateFromClerk()
process.exit(1); process.exit(1);
}); });
``` ```
Make sure to replace the `process.env.CLERK_SECRET_KEY` with your own Clerk secret key. And replace the `import { auth } from "./auth";` with your own auth instance. Feel free to customize the script to your needs.
<Callout type="warning">
The migration script requires Clerk to be fully functional to access user data and accounts.
</Callout>
</Step> </Step>
<Step> <Step>
@@ -381,6 +381,7 @@ migrateFromClerk()
4. Keep Clerk installed and configured until the migration is complete 4. Keep Clerk installed and configured until the migration is complete
</Callout> </Callout>
</Step>
<Step> <Step>
### Verify the migration ### Verify the migration
@@ -417,7 +418,6 @@ migrateFromClerk()
}; };
``` ```
</Step> </Step>
</Step>
<Step> <Step>
### Update the middleware ### Update the middleware
@@ -453,7 +453,6 @@ migrateFromClerk()
pnpm remove @clerk/nextjs @clerk/themes @clerk/types pnpm remove @clerk/nextjs @clerk/themes @clerk/types
``` ```
</Step> </Step>
</Step>
</Steps> </Steps>