Eugene Pentland
Eugene Pentland

Reputation: 3

How do you store user information in firestore if they don't have an account?

I am trying to create an app using firebase auth and firestore where new users can be invited via email to work on a project. The problem is, I do not know the best way to store the temporary user project permissions before they have a uid. I want the user that got invited via email to get access to the project upon opening the link sent to them.

I had tried two different ways

Having a sub collection doc for every user in the project

/project/{projectId}/users/{userId}

When a new user is invited, the userId was set to their email, having a cloud function that triggered when a new user was created to send the invite email to the user. Once the user opened the link, it deleted their user document and a cloud function ran that created a new doc with the users id now that they had once since they were authenticated.

This worked, but left a 10 second period where the user can't interact with the project because the cloud function for making the new user doc is running. Also it just seemed like a bad way to do it.

Having a single document with all of the user information

/project/{projectId}/users/users

users:{
  roles: {
    users_id: 'admin',
    new_user_email: 'admin',
  }
}

This one I was not able to get to work as firestore does not let you create a key with a period in it, but if there was a way around this, it would work as well. I had also set up firestore security rules which made it so they could only edit fields where the key was there uid or their email if they were not an editor/admin.

Upvotes: 0

Views: 716

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

Consider creating an anonymous account in Firebase Authentication first, which requires no input from the user. It will receive a UID that you can use to store data for that account. Then, you can convert that account to a normal account after the signup or login succeeds.

Since you didn't say which mobile platform you're using, I linked you to the web docs, but the procedure is generally the same for each one.

Upvotes: 3

Related Questions