DEV Community

Cover image for 🔥 Firebase Auth Migration 🔥
Mikael
Mikael

Posted on

🔥 Firebase Auth Migration 🔥

Introduction

This article is a short tutorial aimed at giving you a path to migrate users between two Firebase projects (or really any authentication service).

As I passed a good amount of my morning trying to figure out how to do this, I thought spreading the word on the internet could potentially help more people locating it.

The documentation on this matter is hoster by Google here. So if you like to work with docs and do not want to read my little tuto, feel free :)

Tutorial

Step 1: Firebase CLI

In order to perform the import, you will need to use the Firebase command line interface. You can install it without issues on your machine by entering this command into your terminal (npm users)

npm install -g firebase-tools
Enter fullscreen mode Exit fullscreen mode

Continue with the login process and init your firebase repo. Once all is done, you are ready to import/export your auth users.

Step 2: Import users

To import users, go into the Firebase repo you just have inited, and enter the following command

firebase auth:export accounts.json --format=JSON
Enter fullscreen mode Exit fullscreen mode

This will download your current users into your local machine. Make sure the file location is secured, not committed to any git repo and offline. You don't want to leak your users' passwords.

Step 3: Export users to new project

First, switch projects using

firebase use new-project-name
Enter fullscreen mode Exit fullscreen mode

Then go to your Firebase dashboard and go to Authentication > three dots on the top of user card > Hash parameters. You will need this information.

Now to import the users enter (replace the with your config from Firebase)

firebase auth:import accounts.json \
> --hash-algo=<hash_algo> \
> --hash-key=<hash_key> \
> --salt-separator=<sale_sep> \
> --rounds=<rounds> \
> --mem-cost=<mem_cost>

Enter fullscreen mode Exit fullscreen mode

Once successfully migrated, you should receive something like

Processing accounts.json (XXXX bytes)
Starting importing 15678 account(s).
✔  Imported successfully.
Enter fullscreen mode Exit fullscreen mode

All done, you have successfully migrated your users.

Now before you migrate please make sure you have disabled access to your old project for all users in order not to have different data from one project to the other. Also make sure that the apps are correctly updated to use your new project's config. If you respected that, the experience for your users should be seamless.

Have a great day of code!
Mike


About me

I am a partner at MMPG Consulting, a firm active in the custom software development industry in the Spanish and Swiss markets.

For more content, you can add me on LinkedIn or shoot me a DM if you want to discuss specific topics, your software or an idea you want to implement.

Top comments (4)

Collapse
 
lalutero profile image
LA Lutero • Edited

Hi! I have just one question, is it not possible to migrate MFA-related stuff along with the user accounts using Firebase CLI? I am able to do it using Identity Platform Admin SDK, but was wondering if Firebase CLI supports this.

Many thanks.

Collapse
 
mikgross profile image
Mikael

Hey La Lutero, what do you mean by MFA-related stuff?

Collapse
 
exondus profile image
Lichaba

Mikael, you just saved my life with this. Thank you!!!!

Collapse
 
mohammed_hassan_7cfeadac7 profile image
Mohammed Hassan

Does it work for Apple and Google users too?