Transfer Firebase Users to a New Project – Step‑by‑Step Guide
In this article
Yes, you can transfer registered users from one Firebase app to another by exporting them with the Firebase CLI or Admin SDK and importing them into the target project.
What You’ll Need
- Two Firebase projects – the source project (where users currently exist) and the destination project (where you want them).
- Node.js installed on your workstation (version 12 or later).
- Firebase CLI (install with
npm install -g firebase-tools). - Service‑account JSON files for both projects – generate them in the Firebase console under Project Settings > Service accounts > Generate new private key.
- Basic knowledge of JavaScript/Node and the Firebase Admin SDK.
- Optional: a temporary Cloud Storage bucket if you prefer to store the exported JSON file there.
Step‑By‑Step
- Set up a working directory. Create an empty folder on your computer, open a terminal inside it, and run
npm init -yto create apackage.jsonfile. - Install the Admin SDK. Execute
npm install firebase-admin. This library lets you read and write authentication data programmatically. - Place the service‑account keys. Save the JSON key from the source project as
source-key.jsonand the one from the destination project asdest-key.jsoninside the working directory. Keep them private. - Create an export script. In the same folder, create a file named
exportUsers.jswith the following content:
This script pulls every user record (including UID, email, phone, custom claims, and provider data) and writes them toconst admin = require('firebase-admin'); const fs = require('fs'); admin.initializeApp({ credential: admin.credential.cert(require('./source-key.json')) }); const auth = admin.auth(); const users = []; function listAllUsers(nextPageToken) { return auth.listUsers(1000, nextPageToken) .then((result) => { result.users.forEach((userRecord) => users.push(userRecord.toJSON())); if (result.pageToken) { return listAllUsers(result.pageToken); } return users; }) .catch((error) => { console.error('Error listing users:', error); }); } listAllUsers() .then(() => { fs.writeFileSync('usersExport.json', JSON.stringify(users, null, 2)); console.log('Exported', users.length, 'users to usersExport.json'); });usersExport.json. - Run the export. In the terminal, execute
node exportUsers.js. Wait until the script reports the total number of exported users. - Verify the export file. Open
usersExport.jsonin a code editor. You should see an array of JSON objects. Confirm that sensitive fields such aspasswordHashandpasswordSaltare present – they are required for a true migration. - Prepare the import script. Create a new file called
importUsers.jsand paste the following code:const admin = require('firebase-admin'); const fs = require('fs'); admin.initializeApp({ credential: admin.credential.cert(require('./dest-key.json')) }); const auth = admin.auth(); const users = JSON.parse(fs.readFileSync('usersExport.json')); async function importBatch(batch) { try { const result = await auth.importUsers(batch, { hash: { algorithm: 'SHA256', // The following fields must match the hashing parameters used in the source project. // If you used a different algorithm, adjust accordingly. rounds: 0, memoryCost: 0, saltSeparator: '' } }); console.log('Imported', result.successCount, 'users,', result.failureCount, 'failures'); result.errors && result.errors.forEach(err => console.error(err)); } catch (e) { console.error('Import error:', e); } } (async () => { const BATCH_SIZE = 1000; // Firebase limits import to 1000 users per call. for (let i = 0; i < users.length; i += BATCH_SIZE) { const batch = users.slice(i, i + BATCH_SIZE).map(u => ({ uid: u.uid, email: u.email, emailVerified: u.emailVerified, phoneNumber: u.phoneNumber, displayName: u.displayName, photoURL: u.photoURL, disabled: u.disabled, customClaims: u.customClaims, providerData: u.providerData, passwordHash: u.passwordHash ? Buffer.from(u.passwordHash, 'base64') : undefined, passwordSalt: u.passwordSalt ? Buffer.from(u.passwordSalt, 'base64') : undefined, })); await importBatch(batch); } })();Important: The
hashobject must reflect the hashing algorithm used in the source project. Most new projects useSCRYPTorHMAC_SHA256. If you are unsure, check the source project's Authentication > Sign‑in method > Password hashing settings. - Adjust hashing parameters. Replace the placeholder values in the
hashobject with the exact algorithm, key, salt separator, rounds, and memory cost from the source project. You can find these values in the Firebase console under Authentication > Settings > Password hashing. - Run the import. Execute
node importUsers.js. The script will process users in batches of 1,000. Monitor the console output for any failures. - Validate the migration. After the script finishes, open the destination project's Firebase console, go to Authentication > Users, and verify that the expected number of accounts appears. Spot‑check a few accounts to ensure emails, phone numbers, and custom claims transferred correctly.
- Update client apps. If the destination project uses a different API key or OAuth client ID, update your mobile/web apps' configuration files (e.g.,
google-services.json,GoogleService-Info.plist, or Firebase config objects) so they point to the new project. - Disable the old project (optional). Once you are confident the new project works, you may disable sign‑in for the source project to prevent new accounts from being created there. This can be done in Authentication > Sign‑in method by toggling the providers off.
Common Mistakes
- Skipping the hashing configuration. Importing users without providing the correct hash algorithm will cause every password to be marked as invalid, forcing users to reset passwords.
- Exporting only UID and email. The export script must include
passwordHashandpasswordSalt. Leaving them out results in accounts that cannot be signed into. - Exceeding the 1000‑user batch limit. The Admin SDK will reject batches larger than 1,000 users. Always split the array into chunks.
- Using the wrong service‑account key. Mixing up source and destination keys will either export from the wrong project or attempt to import into the wrong one.
- Forgetting to update client configuration. Apps that still point to the old project will continue to authenticate against the source, defeating the migration.
Tips
- Run the export and import scripts on a machine with a stable internet connection; large user bases can take several minutes per batch.
- Store the exported
usersExport.jsonin a secure location (e.g., encrypted storage) because it contains password hashes. - If you have more than 10,000 users, consider running the import script on a Cloud Function or Compute Engine instance to avoid local time‑outs.
- Set
disabled: truefor any accounts that you do not want active immediately; you can enable them later from the console. - Use the
--debugflag with the Firebase CLI (firebase --debug) if you need detailed logs during the process.
Troubleshooting
- Import fails with “invalid password hash”. Verify that the
hash.algorithmand all related parameters exactly match the source project's settings. A mismatch will cause this error. - Script hangs on
listUsers. Check that the service‑account key has thefirebaseauth.adminpermission. Regenerate the key if necessary. - Only a fraction of users appear in the destination console. Look at the console output for
failureCount. Common causes are duplicate UIDs or missing required fields. Resolve duplicates by adjusting the UID in the export file before re‑importing. - Network time‑outs for large exports. Add a small delay between batch imports (e.g.,
await new Promise(r => setTimeout(r, 500));) to stay under Firebase rate limits. - Clients receive “ERROR/INVALID/API/KEY”. Ensure the app’s
google-services.jsonorGoogleService-Info.plistcorresponds to the destination project’s API key.
Frequently Asked Questions
Can I transfer users without their passwords?
If you omit passwordHash and passwordSalt, the imported accounts will exist but users will be forced to reset their passwords via the “forgot password” flow.
Is there a limit to how many users I can migrate?
The Admin SDK imposes a 1,000‑user batch limit for imports, but you can run as many batches as needed. Firebase does not impose a total‑user cap for migration.
Do custom claims survive the migration?
Yes. The export script includes the customClaims field, and the import script writes it back, preserving role‑based access settings.
What if I have users signed in with Google or Facebook?
Provider data (e.g., providerId, uid, displayName) is exported and re‑imported, so federated sign‑in continues to work after migration.
Do I need to inform users before moving their accounts?
While not technically required, it is good practice to notify users of the upcoming change, especially if you plan to reset passwords or temporarily disable sign‑in.
Can I automate this process for future projects?
Yes. Wrap the export and import scripts in a CI/CD pipeline or Cloud Build job, passing the appropriate service‑account keys as secrets.