Reputation: 201
I am trying to sign up the user with firebase . as shown below.
here is the imports
import { auth } from "firebase/auth";
import "firebase/firestore";
import firebase from "../DataBase/FireBase/FireBase";
import firebase from "../DataBase/FireBase/FireBase";
const [FullName, setFullName] = useState("");
const [Email, setEmail] = useState("");
const [Password, setPassword] = useState("");
const signUp = async () => {
try {
await firebase.auth().createUserWithEmailAndPassword(Email, Password);
const currentUser = firebase.auth().currentUser;
const db = firebase.firestore();
db.collection("users")
.doc(currentUser.uid)
.set({
email: currentUser.email,
FullName,
});
} catch (err) {
console.log(err)
alert("There is something wrong!!!!", err.message);
}
}
the user actually can sign up. but the data is not save to the firestore database and no errors . any suggestions please.
Upvotes: 0
Views: 1200
Reputation: 1
It finally worked for me that not using the set method would work perfectly if the add method was used. for example
await db.collection("users")
.add({
email: Email,
name:FullName,
});
Upvotes: 0
Reputation: 50830
When your security rules are set to allow write: if false;
then no one except the Admin SDK can write to your database. You can changed the value to true but then your data is available to anyone on the internet. Ideally you might want to restrict users to their own documents only so in that case try these security rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}
Now users can read/write on documents where the document ID is equal to their UID. You can read more about security rules in the documentation
Upvotes: 1