邮递员中的Javascript :( 500内部服务器错误)

时间:2020-05-27 15:00:57

标签: javascript express google-cloud-firestore google-cloud-functions postman

我使用的材料

  • windows10
  • Firebase(消防站)
  • 邮递员
  • JavaScript,表达

情况

我试图注册Firebase并在Firestore上进行数据制作。但是发生内部错误。有人确认我的密码吗?

index.js

// Signup route 
app.post('/signup', (req,res) => {
  const newUser = {
    email: req.body.email,
    password: req.body.password,
    confirmPassward: req.body.confirmPassword,
    handle: req.body.handle
  };

  //TODO  validate data   
  let token, userId;
  db.doc(`/users/${newUser.handle}`)
    .get()
      .then(doc => {
        if(doc.exists) {
          return res.status(400).json({ hanldle: 'this hanlde is already taken'});
        }else {
          return firebase()
        .auth()
        .createUserWithEmailAndPassword(newUser.email, newUser.password);
        }
      })

    .then((data) => {
       userId = data.user.uid;
      return data.usergetIdToken()
    })

    .then( ( idToken ) => {
      token = idToken ;
      const userCredentials = {
        handle: newUser.handle,
        email: newUser.email,
        createdAt: new Date().toISOString(),
        userId 
      };
      return db.doc(`/users/${newUser.handle}`).set(userCredentials);
    })
    .then(() => {
      return res.status(201).json({ token });
    })
    .catch(err => {
      if(err.code === 'auth/email=already-in-use') {
        return res.status(400).json({ email: 'email is alread is used '})
      } else { 
        return res.status(500).json({ err : err.code });
      }
    });
});

exports.api = functions.https.onRequest(app); 

我的控制台Visual Studio

!  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
i  functions: Beginning execution of "api"
!  External network resource requested!
   - URL: "http://169.254.169.254/computeMetadata/v1/instance"
 - Be careful, this may be a production service.
!  External network resource requested!
   - URL: "http://metadata.google.internal./computeMetadata/v1/instance"
 - Be careful, this may be a production service.
i  functions: Finished "api" in ~9s
i  functions: Beginning execution of "api"
i  functions: Finished "api" in ~8s

邮递员

enter image description here

0 个答案:

没有答案