首页 > 解决方案 > 获取帖子后,我的令牌没有出现在我的 BDD 上

问题描述

我用 aws sns 设置了我所有的通知环境。当我进行测试时,一切正常。下一步,我必须在我的 bdd 上注册令牌。

所以我在我的节点 js 应用程序上做了我的路由: router.post("/postFcmToken", connexionController.postFcmToken);

postFcmToken: (req, res) => {
    User.updateOne(
      { email: req.body.email },
      {
      $set: {fcmToken: req.body.fcmToken}
      },

      (err, data) => {
        if (err) {
          console.log(err);
          res.json({
            message: "une erreur s'est produite dans l'envoi du token",
          });
        } else {
          console.log(data)
          res.json({
            message: req.body.fcmToken,
          });
        }
      }
    );
  },
};

我在 index.js 上捕获了我的令牌

PushNotification.configure({
    // (optional) Called when Token is generated (iOS and Android)
    onRegister: async function (token) {
      console.log("TOKEN:", token);
      await AsyncStorage.setItem("tokenFcm", JSON.stringify(token))
    },

然后我在我的反应本机应用程序上获取我的路线:

const data = {
                fcmToken: await AsyncStorage.getItem("tokenFcm")
              };
          
              const headers = new Headers({
                'Content-Type': 'application/json',
                'X-Requested-With': 'XMLHttpRequest',
              });
          
              const options = {
                method: 'POST',
                body:data ,
                headers: headers,
              };
          
              fetch('http://localhost:8080/connexion/postFcmToken', options)
                .then((response) => {
                  return response.json()
                }).then(
                  (responseObject) =>{
                    console.log("token", responseObject)
                  }
                )
          
            this.props.navigation.navigate('HomePage');
           }
           

我没有错误,我的后端有一个代码 200,但令牌没有在我的 BDD 上注册。当我在我的后端控制台记录数据时,我有:

POST /connexion/postFcmToken 200 57.040 ms - 2
{
  n: 0,
  nModified: 0,
  opTime: {
    ts: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1620388505 },
    t: 11
  },
  electionId: 7fffffff000000000000000b,
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1620388505 },
    signature: { hash: [Binary], keyId: [Long] }
  },
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1620388505 }
}

标签: node.jsreact-nativetoken

解决方案


推荐阅读