**In my crud project the admin adds the user in the docs as well as in auth by normal sdk would replace the current user so i tried admin sdk but writing the cloud functions and calling is getting complex as im new to firebase. i got this got from fellow stackoverflow's thread modified it for my convenience but doesn't seems to be working. **
I deployed the function locally using "firebase serve"
cloud function
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.createUser = functions.firestore
.document('Teamchers/{userId}')
.onCreate(async (snap, context) => {
const userId = context.params.userId;
const newUser = await admin.auth().createUser({
disabled: false,
username: snap.get('UserName'),
email: snap.get('email'),
password: snap.get('password'),
subjectname: snap.get('subjectname')
});
return admin.firestore().collection('Teamchers').doc(userId).delete();
});
calling it
const createUser = firebase.functions().httpsCallable('createUser');
const handleadd = async (e) =>{
e.preventDefault();
try{
createUser({userData: data}).then(result => {
console.log(data);
});
addDoc(collection(db, "Courses" , "Teachers", data.subjectname ), {
...data,
timestamp: serverTimestamp(),
});
alert("Faculty added succesfully")
} catch (e){
console.log(e.message)
}
}