小编Jea*_*ean的帖子

通过 Axios 向 Firebase 云函数发送 POST 请求

我尝试向 Firebase 函数发送一个简单的请求,但每次都会出现相同的错误......显然,Firebase 函数没有收到我想从 Axios 请求传输的数据。

这是 Firebase 功能:

[...] // Some imports

exports.completeProfile = functions.https.onRequest((req, res) => {

  // Debug
  console.log(req); 
  console.log(req.body);
  console.log(req.method);
  console.log("Test: " + userId + ", " + profilePicture + ", " + username);

  // We recover the data
  const userId = req.body.userId; // return "undefined"
  const profilePicture = req.body.profilePicture; // return "undefined"
  const username = req.body.username; // return "undefined"

  // we're checking to see if they've been transferred
  if (!userId || !profilePicture || !username) { …
Run Code Online (Sandbox Code Playgroud)

javascript rest firebase google-cloud-functions axios

2
推荐指数
1
解决办法
6015
查看次数

Undefined不是this.setState的函数

我创建了一个简单的登录页面,一旦按下该按钮,就会执行以下功能:

login = (email, password, navigate) => {
  this.setState({ loginButtonPressed: true });
  firebase
    .auth()
    .signInWithEmailAndPassword(email, password)
    .then(function(user) {
      navigate('Profile');
    })
    .catch(function(error) {
      this.setState({ loginButtonPressed: false });
      Alert.alert(error.toString());
    });
};
Run Code Online (Sandbox Code Playgroud)

一旦被调用,它就会执行"this.setState({loginButtonPressed:true})",因为按钮会改变形状(它被标记为按下).但是我得到以下错误:Undefined不是this.setState函数.

怎么解决这个问题?谢谢你的帮助.

javascript firebase reactjs react-native firebase-authentication

2
推荐指数
1
解决办法
1169
查看次数