I have the following Cloud Function deployed to my Firebase Project:
exports.createCredentials = functions.https.onCall((data, context) => { if(!context.auth) throw new functions.https.HttpsError('failed-auth', 'You must be authenticated to call this function') const { email, password } = data; if(!(typeof email === 'string')) throw new functions.https.HttpsError('invalid-email', 'Email must be a string') if(!(typeof password === 'string')) throw new functions.https.HttpsError('invalid-password', 'Password must be a string') return admin.auth().createUser({ email, password }) .then(userRecord => { return { userRecord } }) .catch((error) => { throw new functions.https.HttpsError(error.code, error.message) }) }) The problem is that whenever I throw a new functions.https.HttpsError instead of the error being catched in the client as the docs state, I get an internal error code. In my function's log, it shows an unhandled error where I tried calling the HttpsError. Here's an example of the log:
Unhandled error Error: Unknown error status: auth/email-already-exists at new HttpsError (/user_code/node_modules/firebase-functions/lib/providers/https.js:80:19) at admin.auth.createUser.then.catch (/user_code/index.js:26:9) at process._tickDomainCallback (internal/process/next_tick.js:135:7) I know that this type of function rejects an internal error if no HttpsError was thrown, but as far as I know that is not the case in my function. I am programming my front end in React so here's how I call this firebase function:
let options = { email: arquitect.email, password: arquitect.password } let createCredentials = firebase.functions().httpsCallable('createCredentials') createCredentials(options) .then(result => { }) .catch(error => console.log(error)) Is there something I am missing?