Firebase错误:代码:“ auth / user-not-found”

时间:2018-07-14 16:37:59

标签: javascript firebase firebase-authentication firebase-admin

我有一个当前在Firebase中存在的用户,但是我已将JavaScript代码写入getUser,该代码无法运行。

const admin = require('firebase-admin');

module.exports = function(req, res) {
  const UID = String(req.body.uid);
  const YOB = String(req.body.YOB);
  const gender = String(req.body.gender);
  const salary = String(req.body.salary);
  const hoursWorked = String(req.body.hoursWorked);

  admin.auth().getUser(UID)
    .then(userRecord => {
      admin.database().ref('users/' + UID)
        .update({
            YOB: YOB,
            gender: gender,
            salary: salary,
            hoursWorked: hoursWorked
          },
          () => {
            res.send({
              success: true
            });
          });
    })
    .catch((err) => {
      res.status(422).send({
        error: err
      });
    });
}

我正在使用Postman发送带有JSON数据的请求,如下所示:

{
  "UID": "JjeSOpY159Pv0qonNNp200qu7wY2",
  "YOB": "1985",
  "gender": "Female",
  "salary": "20.2",
  "hoursWorked": "8"
}

Firebase:

firebase dashboard

我知道我与firebase的连接稳定,因为我可以使用以下代码创建用户:

    const admin = require('firebase-admin');

    module.exports = function(req, res) {
        admin.auth().createUser({})
            .then(user => res.send(user))
            .catch(err => res.status(422).send({ error: err}));
    }

有人对为什么会发生该错误有任何想法吗?

0 个答案:

没有答案