Import Firebase User with Custom Claims

Viewed 485

I am trying to export and import user using the firebase CLI as per docs available here. My problem is that I want to also export the user claims, or at least be able to include custom claims when importing the user.

Basically to export I run on the CLI:

firebase auth:export test.json --format=json

And to import I run on the CLI:

firebase auth:import test.json \ --hash-algo:scrypt

The exported users don't hold the custom claims information.

At the moment, I am working with 2 custom claims, admin and access, pretty much as described here.

The problem is that I was not able to include the claims on the file without having an error returned. Is it feasible to import users with custom claims, if not, what is the correct procedure?

1 Answers

If the claims are not exported by the CLI, then you will have to use the Firebase Admin SDK to work with custom claims. Your code will iterate each UID, fetch the claims and store them somewhere, then update the claims when it's time to import.

Related