Я хотел бы получить доступ к внешнему серверу сигналов One, используя обработчик событий «functions.auth.user (). OnCreate ()», только один раз.
но как-то событие проходит дважды.
кто-нибудь скажет мне, что мне здесь не хватает, и что я должен делать.
Код проблемы выглядит следующим образом ...
exports.deviceRegister = functions.auth.user().onCreate(event => {
const user = event.uid;
const deviceToken = db.ref(`/Users/${user}/deviceToken`);
// below event seems to be triggered twice
deviceToken.on("value", function(snapshot) {
var request = require("request");
var options = {
method: 'POST',
url: 'https://onesignal.com/api/v1/players',
headers: {
'cache-control': 'no-cache',
'Content-Type': 'application/json'
},
body: {
app_id: '**************42249fa65d',
identifier: snapshot.val(),
language: 'en',
timezone: -28800,
game_version: '1.0',
device_os: '7.0.4',
device_type: 0,
device_model: 'iPhone',
tags: { a: '1', foo: 'bar' }
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
// this console.log runs twice
console.log(body);
});
},
function(errorObject) {
console.log("The read failed: " + errorObject.code);
});
})
Я очень благодарен за вашу помощь и поддержку.