Receiving returned data from firebase callable functions

后端 未结 1 739
感动是毒
感动是毒 2021-01-13 20:26

I\'m playing with Callable HTTPS-functions in iOS. I\'ve created and deployed the following function:

export const generateLoginToken = functions.https.onCal         


        
相关标签:
1条回答
  • 2021-01-13 20:48

    Yikes! The issue was that I forgot to return the actual promise from the cloud function. This function is working:

    export const generateLoginToken = functions.https.onCall((data, context) => {
    
        const uid = data.user_id
        if (!(typeof uid === 'string') || uid.length === 0) {
            throw new functions.https.HttpsError('invalid-argument', 'The function must be called with one argument "user_id" ');
        }
    
        return admin.auth().createCustomToken(uid)
        .then((token) => {
            console.log("Did create custom token:", token)
            return { text: "some_data" };
        }).catch((error) => {
            console.log("Error creating custom token:", error)
            throw new functions.https.HttpsError('internal', 'createCustomToken(uid) has failed for some reason')
        })
    })
    
    0 讨论(0)
提交回复
热议问题