We are going to need to use Cloud Functions. We can have a serverless cloud function that triggers whenever the "onCreate" event happens when the user decides to create new account using firebase auth.
// from gpt
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.createUserDocument = functions.auth.user().onCreate((user) => {
// user parameter contains the auth user details
const uid = user.uid;
const email = user.email; // Assuming the user registered with an email
// Reference to Firestore to create a new document in the users collection
const db = admin.firestore();
const userRef = db.collection('users').doc(uid);
return userRef.set({
email: email,
// Add other fields as necessary
})
.then(() => {
console.log(`Successfully created user document for UID: ${uid}`);
return null;
})
.catch(error => {
console.error("Error creating user document:", error);
throw new functions.https.HttpsError('unknown', 'Failed to create user document', error);
});
});
There's also a firebase extension that does this same thing.
We are going to need to use Cloud Functions. We can have a serverless cloud function that triggers whenever the "onCreate" event happens when the user decides to create new account using firebase auth.
There's also a firebase extension that does this same thing.