Step16 Create User in Firestore
Goal of this step
- Create user data in firestore.
Why?
Why do we need to create firestore user? Is firebase authentication user not enough?
- Firebase auth stores information only about authentication.
- We want to store data like name, updatedAt etc...
- We want to store relationship with User and Post in firestore in a later step.
Install Firestore package
https://pub.dev/packages/cloud_firestore
*NOTE!
Please use this or above version. => Important new feature collectionGroup
added.
Make firestore database
Visit: https://console.firebase.google.com
And make firestore database in "test mode".
Add Firestore code
Check the meaning of code
Let's first check the official example code. https://pub.dev/packages/cloud_firestore#usage
This is a code to make a new book.
If you don't set document()
id blank, firestore automatically create documentID for you.
But, in our example, I set the user documentID equal to the Firebase Auth user id.
By doing this, It will be easy to fetch information related to the current logged-in user.
Test it.
Please register new test user from Flutter App.
Then, Check it in console: https://console.firebase.google.com
Memo of Error in this step
debug console
=> flutter clean
https://github.com/flutter/flutter/issues/13971