This question already has answers here:
How to save extra info during user signup process using firebase authentication
(4 answers)
Adding extra information to registration user Firebase
(1 answer)
Closed 2 years ago.
I'm trying to add more fields to accounts:signUp e.i
fields needed: firstname surname phone...
https://firebase.google.com/docs/reference/rest/auth#section-create-email-password
so far I can pass the email and password and a user will be created, how do I add more fields? and store that information in a users collection in cloudfirestore?
Firebase Auth does not have a facility for storing arbitrary user data along with an account. You're supposed to use a database to store that, and link the record you store there to the user ID that Firebase Auth assigns to the user.
Related
This question already has answers here:
How to allow only particular fields of a firestore document to be accessed publicly
(2 answers)
Can I restrict certain fields in firestore database to be only fetched by firebase admin?
(2 answers)
Closed 2 years ago.
I am trying to implement security rule to limit users to access only specific fields inside a document. My data structure goes like this:
document {
name: John,
dob: 1994,
email: john#hotmail.com
}
I want to limit the name field to read, write by owner; dob field to read by owner, create by owner; email to read by owner, update by owner
I read the documentation, and it seems that I can only control access of a specific document with security rules. It didn't mention anything to allow access to a specific field. What I should do in order to allow access to specific fields inside a document?
Security rules can't be used to limit access to individual fields in a document. If a user has direct read access to a document, they can always read every field in the document.
Your only alternatives here are:
Split the restricted fields into a document in another collection, and protect that collection differently.
Reject direct access to the collection entirely, and force users through an API endpoint that strips out the restricted fields based on the user's identity, which was passed to the endpoint.
This question already has answers here:
Cloud Firestore: Enforcing Unique User Names
(8 answers)
Closed 3 years ago.
I am currently trying to verify before a user creates data in the database if the data exists. Even unter an other Document id.
Like this: User creates data, firestore rules gets all documents in collection and checks if the property name is the same as from the user provided. If yes, return unauthorized access.
At this point I have:
function checkIfCatExists(){
return get(/databases/$(database)/documents/category/$(documents)).data.name != null;
}
But this does not work. Do you guys have an idea? I could create a function for that but I want to do as much as possible with rules.
There is no way to search a collection for a specific value in security rules, as that operation wouldn't scale.
If you want to ensure unique user names, you'll have to create a collection where you use the user names as the key. You can then use the exists function in your security rules, to check if the name already exists in the collection.
Also see:
Cloud Firestore: Enforcing Unique User Names
Firestore security rule to check if character username already exists
Firestore security rules - can I query for a document with specific fields?
I want to write a rule that will don't allow add same document second time
This question already has an answer here:
Post request to firebase without unique key
(1 answer)
Closed 3 years ago.
I'm using Firebase Realtime Database integrated in a mobile app and web panel. By default, a unique ID on Realtime DB is generated on this format: -Lup7ey2xRPO9Owm67xM
When creating new register through the Firebase panel, i can customize the unique id with GUID.
{
"0a921e40-5959-43bc-b2be-a65f6712288d": {
"name": "Test"
},
}
However, after call Rest API, with Postman or on my backend, the unique ID is generated by default on Firebase:
{
"-LupIEooOPXAzbc--dB_": {
"name": "Test 2"
},
}
Is it a possible configure Firebase do generate unique ids on format GUID? Replacing default format?
The documentation for the REST API says that using POST is the equivalent of a push operation, which always generates that random push ID. If you want to specify your own name for the node to add, you should be using a PUT request instead and using the client-generated ID in the path for the update.
This question already has answers here:
Test if a data exist in Firebase
(3 answers)
Closed 4 years ago.
I am using angularfire2 wth my ionic app and have sign in with facebook enabled.
When first time a user logs in using the fb then i naturally dnt have any record of it in my firebase DB. I want to create a user node using the facebook returned uid as the node.
The way i can retrieve it is like below. I can check by seeing if it has child objects etc. But is that the way recommended to do this kind of checks? I also don't see how to add subscribe or then to it as i would assume this should be async operation for me to wait until it confims me that user does not exist yet. Please advise
const userRef = this.db.object("/users/" + uid)
Simply building a reference to some location in the database (as shown in the code above) says nothing about whether or not data exists at that location. The location needs to be queried in order to figure out of data exists there.
The sample code get from firebase web API document.
var starCountRef = firebase.database().ref('posts/' + postId + '/starCount');
starCountRef.on('value', function(snapshot) {
updateStarCount(postElement, snapshot.val());
});
This question already has answers here:
Getting the user id from a database trigger in Cloud Functions for Firebase?
(2 answers)
Closed 5 years ago.
Is is possible to get the user UID of the user who wrote/updated/deleted data from the database?
When you are using Firebase authentication you can get the uid of the authenticated user using the following lines of code:
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
if (firebaseUser != null) {
String uid = firebaseUser.getUid();
}
On the other hand, you need to know that Firebase does not store meta-data or other informations regarding write operation. To achieve this, you need to create your own mechanism.
In your case, when a user creates a record, store his uid on a location from where you can query for that particular uid and use it for what you want.
In case you are trying to determine this within Cloud Functions i recomand you take a look at Firebase Cloud Functions and at jacobawenger's answer from this post