1

I just ran a test of Auth.auth().signInAnonymously and printed the uid of the anonymously created User. I then looked up that ID in my Users collection and didn't find a record. Is that User document only created when you convert them to non-anonymous?

Thanks.

Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151

1 Answers1

1

Is that User document only created when you convert them to non-anonymous?

No, the user will appear in the database only when you'll add it. Firebase authentication does not write any data to your Cloud Firestore database.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Got it. Thanks Alex. When I do requests, do I need to do anything additional with this user or its `uid`? – Zack Shapiro Nov 27 '18 at 15:56
  • You're welcome Zack! If you need to add some details to the user object, you can use the `uid` as a unique identifier between your users. `Firestore-root -> users (collection) -> uid (document)`. – Alex Mamo Nov 27 '18 at 15:59
  • Thanks. My app is in a strange state where we're migrating off of Parse and onto Firestore, so right now there's some middle-of-the-road behavior where we're still using Parse as the main user store but I want to take advantage of Firebase/Firestore's security features with anonymous users. We also have a User object in Firestore with some very basic info that lets use identify Firestore user data and relate it to the Parse user data. So that's why I was asking about if that anonymous id is sent in the auth headers – Zack Shapiro Nov 27 '18 at 16:03
  • I understand now. Is a good to choice to use this anonymous authentication feature, go ahead with that. – Alex Mamo Nov 27 '18 at 16:05
  • Definitely. Really glad Firebase/Firestore has that. Just to ask this one last time directly for me and future people who come across this, once the anonymous user has been signed in, when I do requests to get documents, set data, etc, are those "authenticated requests," i.e. do I have automatically have a `request.auth` object being sent along with my request so my security rules can account for authenticated vs. unauthenticated requests? – Zack Shapiro Nov 27 '18 at 16:07
  • Once you are authentificated (anonymous or non-anonymous), yes, those are "authenticated requests". Yes, you have a FirebaseUser object for that. See **[here](https://stackoverflow.com/questions/50885891/one-time-login-in-app-firebaseauth)** more informations on how to achieve this using `FirebaseAuth.AuthStateListener`. Regarding the rules, there is nothing created automatically, you should write your own specific rules. – Alex Mamo Nov 27 '18 at 16:16