Adding users to another Firebase project

108 views
Skip to first unread message

it...@picniic.com

unread,
Apr 8, 2019, 6:54:27 PM4/8/19
to Firebase Google Group
We have used Firebase realtime DB with good success, we want to start migrating/using Firestore, however we are all ready using Cloud Datastore and App Engine in the same project so I could not enable Firestore in the project.  We would use both realtime and Firestore in tandem.

Questions:
  1. If we remove our use of Cloud Datastore and App Engine in the project would we be able to enable Firestore?
  2. I started investing using a separate project and having our apps connect to 2 Firebase projects.  We are using Firebase's email/password authentication.  The problem is how to manage authentication. Is there a recommended way to handle this? 
  3. I looked into exporting an existing user from the existing project into new project on demand.  My plan is in node.js code to use the admin.auth().getUser() function to get a user's info then add the user into the new project using admin.auth().importUsers.  One observation is the user object returned does not have the same data returned for passwordHash and passwordSalt for the same user in the auth().listUsers() function.  Should the user's password hash and salt values be the same regardless of which function returned the data?
UserRecord {
  uid: '00MD9Pw5OPdVjwvqFplPrULHEr62',
 ...
  passwordHash: 'UkVEQUNURUQ=',
  passwordSalt: undefined,
  customClaims: undefined,
  tokensValidAfterTime: 'Mon, 18 Sep 2017 23:52:09 GMT'
}

If I call auth().listUsers, the UserRecords returned 

{
  uid: '00MD9Pw5OPdVjwvqFplPrULHEr62',
  ...
  passwordHash: 'sBO_zKBmxJ9YTT2rR5UAtezNGW2ziGmj_pegJJZPuurT_iNsXFxQrnVIAaqTqISXMfSRybzATjKNGT_k5CmmWA==',
  passwordSalt: 'YnEEloAZILEM3A==',
  customClaims: undefined,
  tokensValidAfterTime: 'Mon, 18 Sep 2017 23:52:09 GMT'

 

Hiranya Jayathilaka

unread,
Apr 9, 2019, 1:11:28 AM4/9/19
to fireba...@googlegroups.com
On Mon, Apr 8, 2019 at 3:54 PM <it...@picniic.com> wrote:
We have used Firebase realtime DB with good success, we want to start migrating/using Firestore, however we are all ready using Cloud Datastore and App Engine in the same project so I could not enable Firestore in the project.  We would use both realtime and Firestore in tandem.

Questions:
  1. If we remove our use of Cloud Datastore and App Engine in the project would we be able to enable Firestore?
  2. I started investing using a separate project and having our apps connect to 2 Firebase projects.  We are using Firebase's email/password authentication.  The problem is how to manage authentication. Is there a recommended way to handle this? 
  3. I looked into exporting an existing user from the existing project into new project on demand.  My plan is in node.js code to use the admin.auth().getUser() function to get a user's info then add the user into the new project using admin.auth().importUsers.  One observation is the user object returned does not have the same data returned for passwordHash and passwordSalt for the same user in the auth().listUsers() function.  Should the user's password hash and salt values be the same regardless of which function returned the data?
Do you actually see passwordHash and passwordSalt on the UserRecord returned by getUser()? That's not supposed to happen. Can you show a full example of your code?

Thanks,
Hiranya
 
UserRecord {
  uid: '00MD9Pw5OPdVjwvqFplPrULHEr62',
 ...
  passwordHash: 'UkVEQUNURUQ=',
  passwordSalt: undefined,
  customClaims: undefined,
  tokensValidAfterTime: 'Mon, 18 Sep 2017 23:52:09 GMT'
}

If I call auth().listUsers, the UserRecords returned 

{
  uid: '00MD9Pw5OPdVjwvqFplPrULHEr62',
  ...
  passwordHash: 'sBO_zKBmxJ9YTT2rR5UAtezNGW2ziGmj_pegJJZPuurT_iNsXFxQrnVIAaqTqISXMfSRybzATjKNGT_k5CmmWA==',
  passwordSalt: 'YnEEloAZILEM3A==',
  customClaims: undefined,
  tokensValidAfterTime: 'Mon, 18 Sep 2017 23:52:09 GMT'

 

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/415b3ecb-627d-4f5b-9b5b-18db1bfa7199%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Hiranya Jayathilaka | Software Engineer | h...@google.com | 650-203-0128

Hiranya Jayathilaka

unread,
Apr 9, 2019, 1:27:20 AM4/9/19
to fireba...@googlegroups.com
I think there's a bug here. I've reported it at https://github.com/firebase/firebase-admin-node/issues/501

getUser() API is not designed to support user account migration scenarios. So I don't think you can use it the way you're suggesting. As far as I know there's currently no API for migrating user accounts on-demand. The existing APIs (listUsers and importUsers) only support bulk migrations.

it...@picniic.com

unread,
Apr 9, 2019, 11:30:13 PM4/9/19
to Firebase Google Group
Here is a code sample, getUser() and getUserByEmail() both return same results for the same user.  Still looking for insight into my first 2 questions. thanks.

function getUserByEmail(userEmail) {
  return FirebaseAdmin.auth()
    .getUserByEmail(userEmail)
    .then(function(userRecord) {
      // See the UserRecord reference doc for the contents of userRecord.
      console.log("Successfully fetched user data:\n", userRecord.toJSON());
      return userRecord;
    })
    .catch(function(error) {
      console.log("Error fetching user data:", error);
      return null;
    });
}


Hiranya Jayathilaka

unread,
Apr 10, 2019, 12:45:31 AM4/10/19
to fireba...@googlegroups.com
For 1, I'm pretty sure the answer is no. If datastore has been ever enabled in a project, it cannot ever be used for Firestore afaik.

Question 2 is not very clear to me. How do you connect an app to two different projects? Using 2 separate FirebaseApp instances? In any case, there's no easy way to share auth across projects.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages