In my firebase application, I am attempting to create a new user by transferring data from the UI to a callable function. The process involves:
- Creating a user account using an email and password.
- Adding a display name followed by creating a profile in a user collection.
- Sending a confirmation email to the user; however, I encountered an error message that stated: "Unknown error status: Error: The uid must be a non-empty string with at most 128 characters."
const db = admin.firestore();
exports.createUser = functions.https.onCall((data, context) => {
return admin.auth().createUser({
email: data.email,
password: data.password,
displayName: data.displayName,
}).then(user => {
return db.doc('users/' + user.uid).set({
email: data.email,
displayName: data.displayName,
type: data.type,
organization: data.organization
});
})
.then(user => {
let uid = user.uid;
if (data.type === "admin") {
return admin.auth().setCustomUserClaims(uid, {
isAdmin: true,
})
} else {
return admin.auth().setCustomUserClaims(uid, {
isAdmin: false,
})
}
})
.then(user => {
return user.sendEmailVerification();
})
.catch(error => {
new functions.https.HttpsError(error);
});
})
Below is the code snippet from my React JS frontend:
let createUser = functions.httpsCallable('createUser')
createUser({
email: this.state.email,
password: this.state.password,
displayName: this.state.name,
type: this.state.type,
organization: this.state.organization
})
.then(result => {
console.log(result)
})
.catch(error => {
console.log(error)
})