I am trying to create a document 'users' on my Firestore. Firebase performs its job fantastically, however when creating a new user, Firestore does not properly execute the function and in response it floods the network with 200 status.
In order to try to resolve this issue I deleted the whole firebase project, made a new one from scratch, but nothing was resolved.
On my side it all seems perfectly ok, I followed Google Firestore documentation by the letter. is any of you able to give me an understanding of the issue. Just to be clear in the console no error is displayed.
Here is SignUp.jsx
const handleSubmit = async (e) => {
e.preventDefault();
if (password !== passwordConfirm) {
return setError('Passwords do not match');
}
try {
setError('');
setLoading(true);
const user = await register(email, password);
const uid = user.uid;
console.log(uid);
await addUser(user.email);
console.log('If I see this all went processed');
navigate('/tutorials');
} catch (error) {
console.log(error);
setError('Failed to create an account');
setError(error.message);
}
setLoading(false);
};
Then when addUser(user.email) is invoked, the program goes here
try {
const docRef = await addDoc(collection(db, 'users'), {
email,
htmlCode: '',
cssCode: '',
jsCode: '',
});
console.log('Document written with ID: ', docRef.id);
} catch (e) {
console.error('Error adding document: ', e);
}
};
Then I see no error on console, but a bunch of this 200 status
[
If anyone would like to look at more detailed info I could always provide them. Thank you very much for your help in advance!
--- SOLVED! ---
I had forgotten to mention that in my application I was using a .env.local file for hiding firebase config information that should remain undisclosed. Note that, xxx is replaced to indicate firebase config values.
VITE_FIREBASE_API_KEY=xxx
VITE_AUTH_FIREBASE_AUTH_DOMAIN=xxx
VITE_FIREBASE_PROJECT_ID=xxx
VITE_FIREBASE_STORAGE_BUCKET=xxx
VITE_FIREBASE_MESSAGING_SENDER_ID=xxx
VITE_FIREBASE_APP_ID=xxx
VITE_FIREBASE_MEASUREMENT_ID=xxx
following to firebase.js...
// init app
const firebaseConfig = initializeApp({
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
authDomain: import.meta.VITE_AUTH_FIREBASE_AUTH_DOMAIN,
projectId: import.meta.VITE_FIREBASE_PROJECT_ID,
storageBucket: import.meta.VITE_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.VITE_FIREBASE_MESSAGING_SENDER_ID,
appId: import.meta.VITE_FIREBASE_APP_ID,
measurementId: import.meta.VITE_FIREBASE_MEASUREMENT_ID,
});
this set up seemed to have conflicted somehow.
but if firebase config is set directly on firebase.js as follow...
const firebaseConfig = {
apiKey:'xxx',
authDomain:'xxx',
projectId:'xxx',
storageBucket:'xxx',
messagingSenderId:'xxx',
appId:'xxx',
measurementId:'xxx',
};
Despite I did resolved this problem by using setLogLevel('debug') which ultimately said 'The database (default) does not exist for project undefined' has any of you guys an idea why I had that problem in the first place?