Migrating to Foir
Moving an existing user base to Foir is one command: export your users from the provider you are leaving, then hand the file to foir users import. People whose passwords were stored as bcrypt hashes keep them and sign in with the password they already know. Everybody else sets a password the first time they sign in.
The file
A CSV with a header row, or a JSON array of objects, with one person per row or entry:
| Field | Required | What it holds |
|---|---|---|
email | yes | The address the person signs in with. |
first_name | no | Their first name. |
last_name | no | Their last name. |
password_hash | no | The bcrypt hash their old provider stored: $2a$, $2b$ or $2y$, cost 4 to 31. |
firstName, lastName and passwordHash work too. Any other column or key stops the import before anything is sent, so a misspelt pasword_hash can’t quietly bring everybody in without a password. Remove the columns your export has that Foir doesn’t read.
email,first_name,last_name,password_hash
ana@example.com,Ana,Byrne,$2b$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy
ben@example.com,Ben,,[
{ "email": "ana@example.com", "first_name": "Ana", "password_hash": "$2b$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy" },
{ "email": "ben@example.com" }
]Run it
Check the file first. A dry run reads every person and says what an import would do, and changes nothing:
foir users import users.csv --dry-run
foir users import users.csvEach person gets one of three answers:
- created: a new user in the project, holding the hash they had if the row gave one.
- already held the address: somebody in the project already signs in with that email. They are left exactly as they are, password included, so running the same file twice is safe.
- refused: with the reason, for example a hash that isn’t bcrypt. Fix the row and run the file again; the people already created come back as “already held the address”.
The CLI sends a large file in batches of 1,000. Add --json for every person’s answer, with the new user’s id, to feed into your own records.
The import emails nobody. People find out from you, and sign in when they next visit your app.
Importing needs users:create and users:setup: a password hash is a way into somebody’s account, so bringing one in is charged like choosing a person’s first password.
Passwords that aren’t bcrypt
Leave password_hash empty for anybody whose old provider hashed with something else (scrypt, argon2, PBKDF2). They are created with no password. When they first sign in they choose one with “Forgot password?”, or use a one-time code where the project has codes on. A new project has passwords on and one-time codes off.
This is also the right choice when you’d rather everybody picked a fresh password: import the file with no password_hash column at all.
From Clerk
Clerk’s user export is a CSV that includes each user’s bcrypt password hash.
- Export your users from the Clerk dashboard.
- Keep the email, first name, last name and password hash columns, named as in the file, and remove the rest.
foir users import clerk-users.csv --dry-run, then without--dry-run.- Repoint your app. Clerk’s
<SignIn />becomes hosted sign-in, and where you read Clerk’s session you verify the Foir user access token against the JWKS.
From Better Auth
Better Auth keeps users in your own database, so there is no export step: query the user table for each email and name.
- Write the rows to a CSV with
email,first_nameandlast_name. - Better Auth hashes passwords with scrypt by default, which isn’t bcrypt, so leave
password_hashout. People who signed in with Google or another provider have no password to bring; they sign in with the same provider through Foir. foir users import better-auth-users.csv.- Replace Better Auth’s client and server helpers with hosted sign-in for the sign-in page, and the user access token where you read the Better Auth session.
After you migrate
- Wire lifecycle events. Define an operation that receives the event, then attach it as a hook on
USER_CREATED,USER_UPDATEDandUSER_DELETED, so your systems stay in sync. See Webhooks and Hook Events. An import raisesUSER_CREATEDfor each person it creates. - Choose a session shape. Bearer tokens, or an
HttpOnlycookie via a first-party session. - Watch usage. Imported users count toward MAU once they sign in.