Firebase可调用云函数返回未定义

时间:2019-05-26 07:46:05

标签: javascript firebase google-cloud-functions

我正在创建可调用的云函数,该函数在云Firestore数据库中创建用户个人资料,并添加自定义声明... 我在前端将其称为如下

 let setUpUser = functions.httpsCallable('setUpUser');

...other code

.then(async ()=>{
 try {
     const user = await setUpUser({
       displayName: this.state.name,
       email: user.user.email,
       type: this.state.type,
       organization: this.state.organization
     });
     console.log(user);
 }
 catch (e) {
   console.error(e);
 }
})

和云端功能我尝试调用云端功能并使用下面的代码进行设置

exports.handler = ((data,context,admin,db )=>{
  let uid = context.auth.uid;
  return db.doc('users/'+uid).set({
      displayName:data.displayName,
      email: data.email,
      type:data.type,
      organization:data.organization
    })
  .then(()=>{
    if (data.type === "teacher"){
      return admin.auth().setCustomUserClaims(uid,{
        isTeacher:true,
      })
    }
    return;
  })
  .then(() => {
    return admin.auth().getUser(uid).then((userRecord)=>{
      return userRecord
    })
  })
  .catch(error =>{
    throw new functions.https.HttpsError(error);
  });
})

但是前端的日志是Cannot read property 'user' of undefined

0 个答案:

没有答案