I have a Flutter app where users should be able to join groups and invite others to groups.
We store this group membership by adding each user’s ID (from Firebase Auth, but the same ID is also used in a separate users collection) to the group, and whether the user is pending or has accepted the invite.
I want to be able to invite people who are not currently using the app by sending them an email, and we’d want to track that pending invitation so they can accept it when they sign in.
To do this, I’m assuming I’d need to pre-generate the Auth UID for them. Is there a way to get a pre-generated Auth UID, and then when a user signs up (provided I pass in that ID), have that UID gets used when they actually sign up?
If not, any other way people have been able to store a potential membership for a user who doesn’t exist yet?
2
Answers
No. A UID is generated once the authentication process is successful. You cannot generate UIDs in advance.
A solution might be to send your users emails that will contain authentication codes. All these codes should be present inside your database along with the email to which you have sent the invitation and a timestamp. In this way, you’ll be able to track your users and know how long it took to accept your invitation.
The only way to specify a user ID is by creating the user account using the Firebase Admin SDK on a backend (this will not work using the web and mobile SDKs on the frontend). From the documentation:
You could certainly arrange for your backend to create a new account for the user as they click through to your application, but it won’t be as convenient as creating the user in the app after they launch it.
This may or may not be the thing you want to actually do to solve the problem at hand, but it is an option.