Firebase import users from existing app

It is now possible to export/import users in Firebase v3.x. All you have to do is install Firebase CLI (Firebase Tools), setup a folder on your machine representing tooling mirror for your Firebase project. (as simple as firebase init in the appropriate folder)

To Export: auth:export

To Import: auth:import

Update: At the time I wrote this answer, given example in link above for auth:import has 2 pieces missing: hash key and salt separator, which you can ask from customer support. Maybe they share it with tools or from console in the future.


Update as of 11/2019

  1. Very first step, make sure to install Firebase Tools, the command for this npm install -g firebase-tools, I assume that you have installed Node.js and npm before.

  2. Hit in your terminal firebase login to log in to the account from which you want to export (you might be already logged in btw).

  3. Export your emails and password by using firebase auth:export database.json --project projectName.

  4. Now firebase logout and firebase login to the account where you want to import.

  5. Go to Console -> Project -> Authentication -> Password hash parameter of the project from which you're exporting (this is very important, if you'd take parameters from that one to which you import it won't work).

There you can see something like that:

hash_config {
  algorithm: SCRYPT,
  base64_signer_key: <long string of random characters>,
  base64_salt_separator: <short string of random characters>,
  rounds: 8,
  mem_cost: 14,
}
  1. In your terminal run firebase auth:import database.json --hash-algo=scrypt --rounds=8 --mem-cost=14 --hash-key=<long string of random characters> --salt-separator=<short string of random characters> --project=YOUR_PROJECT_NAME. Note: I didn't use quotes for the strings and it worked out perfectly.

  2. Test your authentication if it works on new environment. Might be obvious, but don't forget to change your firebaseConfig to be on the new project :)

Edit:

To clarify on which Firebase Tools version it works:

$ firebase --version
7.6.1

The current best way to import existing user accounts from another service into Firebase for use within Firebase Simple Login is to call createUser(email, password, callback) for each of the email address / password combinations, provided you have them. There is currently no out-of-the-box way to import user email addresses and password hashes into Firebase Simple Login, though ping [email protected] and there may be a way to do this.

If you already have an existing authentication mechanism that you'd like to continue using, rather than using Firebase Simple Login, check out custom token generation, which will allow you to continue using your existing authentication. This would require you to generate a JSON Web Token (JWT) when each user authenticates, and this token's payload could then be used in your security rules, as described here: https://www.firebase.com/docs/security/security-rules.html.

Tags:

Firebase