hi I’m developing an Android application (preferring Kotlin/Java) and using a block development environment that integrates a specific Firebase Cloud Firestore extension.
My goal is to store user data in the Firestore Users collection. It’s crucial that the document ID for each user matches their UID (User ID) obtained from Firebase Authentication, as my Firestore security rules require userId == request.auth.uid . I tried using the Idriss and Jarlisson extension. Can you tell me which blocks I should use for this purpose? Thanks.
To achieve this you need to use the UID from Firebase Authentication as the document ID when writing to Firestore. This way, your Firestore rules userId == request.auth.uid
will work correctly.
Steps with blocks
-
Get the UID
- After the user signs in with Firebase Authentication, use the block
FirebaseAuth.CurrentUser
→Get Id
(or whichever block your extension provides to fetch the UID). - Store this in a variable, e.g.
global userUID
.
- After the user signs in with Firebase Authentication, use the block
-
Create a dictionary with user data
-
Use the
make a dictionary
block for fields like,"name" → NameTextBox.Text "email" → EmailTextBox.Text "phone" → PhoneTextBox.Text
(you can add more fields as needed).
-
-
Write to Firestore
- Use the Firestore extension block
Set Document
(orStore Document
depending on your extension). - Collection =
"Users"
- Document ID =
global userUID
- Data = dictionary you just made.
- Use the Firestore extension block
when FirebaseAuth.OnSignInSuccess do
set global userUID to FirebaseAuth.CurrentUserID
set userDict to make a dictionary
"name" → NameTextBox.Text
"email" → EmailTextBox.Text
"phone" → PhoneTextBox.Text
call Firestore.SetDocument
collection = "Users"
document = global userUID
data = userDict
This ensures,
- Each user’s data goes to
/Users/{uid}
in Firestore. - Your security rules will allow access only to their own document, since
request.auth.uid
matches the document ID.
Since i don’t have that extension am not able to provide blocks
thnx i try
if you dont use extension where you take this block? call Firestore.SetDocument , i dont have in basic kodular
That’s why i said
Do you have the extansion?
It must contain it by default then add
i dont have default that block
I asked you here
i dont have that block