Home > Enterprise >  Is it possible to import Authentication data to Firebase Emulators?
Is it possible to import Authentication data to Firebase Emulators?

Time:09-13

I periodically update my emulator’s Firestore data to be as close to production as possible.

I recently updated Custom Claims logic with the Auth emulator turned on. None of my users can be accessed from the Admin Auth SDK by uid (as they aren’t in emulators).

Updating claims as per the docs:


getAuth()
  .setCustomUserClaims(uid, { admin: true })
  .then(() => {
    // The new custom claims will propagate to the user's ID token the
    // next time a new one is issued.
  });

I (foolishly) solved this by turning off Auth Emulator which modified Custom Claims for production users while developing and testing.

Is there a way to export Auth Data and import into Emulators, as there is for Firestore?

Or alternatively,

Is there a way to specify uid (to match Firestore) when creating fake users in Auth Emulators?

CodePudding user response:

Is there a way to specify uid (to match Firestore) when creating fake users in Auth Emulators?

You can specify the user ID when using createUser() with Admin SDK. If you have a script that migrates Firestore documents from production to emulator, you can create users in the same using the document IDs.

Alternatively, you can firebase auth:export command to export users from production inn case you just need to read the data from a local file.

If you are just referring to emulator data then you can import dumped data back in emulators by:

firebase emulators:start --import dump_file
  • Related