When using multiple Realtime Databases, Firebase forces you to authenticate each of the databases you want to use. I’ve seen this answered a few times such as here but don’t see any examples of how to handle this for anonymously based sign-ins. Is there a way to take the anonymous authentication from the default Realtime Database and authenticate the same anonymous user on another Realtime Database (retaining the same user ID)?
As additional background, this is for an online game where users are matched to play against other users. One database should be used as a waiting room for the matchmaking whilst the other database would be for the game data itself. Load Perf is regularly meeting 100% as the matchmaking and game data are currently stored in the same database.
At the moment, I can anonymously authenticate a user on the different Realtime Database instances, but the user IDs are different. This is no good, as the user IDs need to be the same across both matchmaking and game data databases.
2
Answers
Firebase Authentication is not related in any way to a Realtime Database. It’s true that you can scale your data in Firebase Realtime Database by splitting your data across multiple instances, but I don’t think that’s what you’re looking for.
In such cases, you should create different nodes for different users. There is no need to create a new instance of the database in this case. Furthermore, Firebase Anonymous Authentication can easily solve your problem because it provides a unique ID for each user. So you can create a node for a user and another different node for the other user.
There is no way to sign the same anonymous user in on multiple devices, nor even on the same device once they sign out.
If you want to allow the user to sign-in on multiple devices, you will have to ask them for their credentials – typically linking those to the existing anonymous account.