Simon
Simon

Reputation: 2538

Export firebase user account emails

I'm having a problem exporting the user account emails from Firebase.

I just revisited an old project I haven't touched in months and I'd like to export the email addresses. I'm in my functions folder, and have done:

 npm install -g firebase-tools

then

 npm install firebase-functions

and

 npm install

No issues here. I then enter:

firebase auth:export save_file.csv --format=csv

and I get the output:

$ firebase auth:export save_file.csv --format=csv
Exporting accounts to save_file.csv

Error: An unexpected error has occurred.

I also read that you can try firebase login --interactive but when I do that I get the error:

Already logged in as ***@gmail.com

How should I go about debugging this/what should I be doing to export the emails? Any ideas?

Thank you.

Edit: I dug into the firebase-debug and the output showed:

[debug] [2020-01-20T21:49:31.847Z] ----------------------------------------------------------------------
[debug] [2020-01-20T21:49:31.849Z] Command:       C:\Program Files\nodejs\node.exe C:\Users\Simon K\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js auth:export save_file.csv --format=csv
[debug] [2020-01-20T21:49:31.849Z] CLI Version:   7.12.1
[debug] [2020-01-20T21:49:31.849Z] Platform:      win32
[debug] [2020-01-20T21:49:31.849Z] Node Version:  v12.7.0
[debug] [2020-01-20T21:49:31.851Z] Time:          Mon Jan 20 2020 16:49:31 GMT-0500 (Eastern Standard Time)
[debug] [2020-01-20T21:49:31.851Z] ----------------------------------------------------------------------
[debug] [2020-01-20T21:49:31.851Z] 
[debug] [2020-01-20T21:49:31.857Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2020-01-20T21:49:31.858Z] > authorizing via signed-in user
[debug] [2020-01-20T21:49:31.859Z] [iam] checking project anonymous-social for permissions ["firebase.projects.get","firebaseauth.users.get"]
[debug] [2020-01-20T21:49:31.860Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-01-20T21:49:31.860Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token  
 <request body omitted>
[debug] [2020-01-20T21:49:32.050Z] <<< HTTP RESPONSE 400
[debug] [2020-01-20T21:49:32.051Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/anonymous-social:testIamPermissions  

[debug] [2020-01-20T21:49:32.183Z] <<< HTTP RESPONSE 401
[debug] [2020-01-20T21:49:32.183Z] <<< HTTP RESPONSE BODY
[debug] [2020-01-20T21:49:32.184Z] [iam] error while checking permissions, command may fail: FirebaseError: HTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
[info] Exporting accounts to save_file.csv
[debug] [2020-01-20T21:49:32.185Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-01-20T21:49:32.185Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token  
 <request body omitted>
[debug] [2020-01-20T21:49:32.332Z] <<< HTTP RESPONSE 400
[debug] [2020-01-20T21:49:32.333Z] >>> HTTP REQUEST POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/downloadAccount  

[debug] [2020-01-20T21:49:32.457Z] <<< HTTP RESPONSE 401
[debug] [2020-01-20T21:49:32.457Z] <<< HTTP RESPONSE BODY
[debug] [2020-01-20T21:49:32.614Z] TypeError: Cannot read property 'code' of undefined
    at C:\Users\Simon K\AppData\Roaming\npm\node_modules\firebase-tools\lib\accountExporter.js:170:26
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
[error] 
[error] Error: An unexpected error has occurred.

Does this make sense?

Upvotes: 1

Views: 2138

Answers (2)

Simon
Simon

Reputation: 2538

For anyone struggling with the same. I ended up having to logout and relogin to firebase. I think my token had expired or something like that.

  • firebase logout

  • firebase login --interactive

I had to login twice for some reason but it worked then!

Upvotes: 3

zkohi
zkohi

Reputation: 2520

Did you run firebase use --add?

Or, could you try any following commands?

  • firebase projects:list
  • firebase use project_id_or_alias
  • --project flag.(firebase auth:export save_file.csv --format=csv --project=project_id_or_alias)

See:

Upvotes: 1

Related Questions