skip to Main Content

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


  1. Is there a way to pre-generate a UID for a new user?

    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.

    Login or Signup to reply.
  2. 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:

    By default, Firebase Authentication will generate a random uid for the new user. If you instead want to specify your own uid for the new user, you can include it as an argument passed to the user creation method:

    getAuth()
      .createUser({
        uid: 'some-uid',
        email: '[email protected]',
        phoneNumber: '+11234567890',
      })
      .then((userRecord) => {
        // See the UserRecord reference doc for the contents of userRecord.
        console.log('Successfully created new user:', userRecord.uid);
      })
      .catch((error) => {
        console.log('Error creating new user:', error);
      });
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search