0

Whenever i'm running "firebase deploy --only functions" it hits up with this error Error occurred while parsing your function triggers.

TypeError: functions.https.onCall(...).then is not a function at Object. (C:\Users\Lenovo\Desktop\Firebase Revision\functions\index.js:11:4) at Module._compile (internal/modules/cjs/loader.js:1158:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load (internal/modules/cjs/loader.js:901:14) at Module.require (internal/modules/cjs/loader.js:1044:19) at require (internal/modules/cjs/helpers.js:77:18) at C:\Users\Lenovo\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:15:15 at Object. (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:53:3) at Module._compile (internal/modules/cjs/loader.js:1158:30)

Following is my code in index.js functions

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.addAdminRole = functions.https.onCall((data,context) => {
    return admin.auth().getUserByEmail(data.email).then(user => {
        return admin.auth().setCustomUserClaims(user.uid,{
            admin: true
        });
    })
}).then(()=>{
    return {
        message: `Success! ${data.email} has been made an admin`
    }
}).catch(err => {
    return err;
})

1 Answer 1

0

You didn't chain the then() method correctly. You should do as follows:

exports.addAdminRole = functions.https.onCall((data, context) => {
    return admin.auth().getUserByEmail(data.email)
        .then(user => {
            return admin.auth().setCustomUserClaims(user.uid, {
                admin: true
            });
        })
        .then(() => {
            return {
                message: `Success! ${data.email} has been made an admin`
            }
        }).catch(err => {
            return err;
        })
})

Note that instead of doing

.catch(err => {
    return err;
})

you should follow the doc on how to handle errors in a Callable Cloud Function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.