0

我正在使用nexmo进行两步身份验证,我计划通过graphl突变来实现这一点,因为我有graphql API并且我无法获得requestId值

  Mutation: {
    signUpFirstStep: async ( parent, { number }, { models, secret }) => 
    {
     const response =  nexmo.verify.request({
        number: number,
        brand: 'Nexmo',
        code_length: '4'
      }, (err, result) => {
        const  requestId  = result.request_id
        return requestId

      });
      console.log(response);  //right here I have undefined
  }
}

我想要的只是获取 requestId 值以在突变中返回它

4

1 回答 1

1

nexmo.verify.request不会返回你想要的。你需要console.log,或者处理你喜欢的 requestId,如果你愿意,(err, result) => {} 你也可以在你内部做res.status(200).send(result);或者res.status(200).send(requestId);用结果或 requestId 回复。

见下文:

Mutation: {
    signUpFirstStep: async ( parent, { number }, { models, secret }) => 
    {
     nexmo.verify.request({
        number: number,
        brand: 'Nexmo',
        code_length: '4'
      }, (err, result) => {

        if(result) {  
          const  requestId  = result.request_id;
          console.log(requestId); // you should console.log or do whatever you are trying to do with the requestId here
        }
      });

  }
}
于 2019-10-18T15:05:49.280 回答