As we transition our MongoDB database to Firebase with Firestore, we are facing the challenge of integrating Firebase authentication for our users. Currently, we store user data in Firestore and want to utilize Firebase authentication for user logins. Each user within our Firestore has a Facebook ID stored in their document, which we aim to use to create an Auth account.
Creating a Facebook user programmatically using cloud functions is not feasible. Our proposed solution involves implementing a cloud function that checks if a new Facebook user's ID already exists in our Firestore when they sign up. However, this approach is hindered by the fact that the authentication UID is set upon creation and cannot be modified. Ideally, we would like the authentication ID to match the user's document name.
Potential Solutions
Introducing a Redirect Collection for New Users
Initially, we considered creating a new collection of documents where Facebook user UIDs would be mapped to their corresponding documents with their original UIDs. However, this would significantly increase read operations and inflate our Firestore bill.
Changing User Document Names
Alternatively, we could rename user documents to align with the authentication UID. This would streamline the process and minimize changes required to handle authenticated users. Yet, updating all references to the user poses a substantial challenge, especially with a large user base.
We are actively searching for solutions to address this issue. Any feedback or suggestions to help guide us in the right direction would be greatly appreciated. Feel free to ask any questions for clarification. Thank you for your interest!