node.js - 获取帖子后,我的令牌没有出现在我的 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 }
}
解决方案
推荐阅读
- python-3.x - 如何在 Python 3 中将字典的键和值从一个函数引用和访问到另一个函数?
- hibernate - 在生产环境中应该使用 hibernate.hbm2ddl.auto 属性的哪个值?
- javascript - 如何通过基于数字的 JavaScript 重定向 URL(如果为 1,则重定向到 A;如果为 2,则重定向到 B...)
- c++ - 使用 GMP 的 while 循环问题
- python - 填充 = 1 的 PyTorch MaxPool2D 意外行为
- java - 运行时找不到 JDBC 类
- python - 如何将字符串作为文件处理以构造 ZipFile 对象?
- windows - 信息正在等待与 npm 的连接...为 MoodleMobile_2 设置开发环境时出错
- php - Laravel 6 Artisan 使特征自定义命令不起作用
- laravel - Docker Redis 无法连接 laravel 和 predis