原因是您检查数据未定义的方式不正确,即以下代码不正确:
if( FB_access_token!==undefined||'undefined' && twitter_username!==undefined||'undefined' && insta_username!==undefined||'undefined' && user_id!==undefined||'undefined' && test_at_src!==undefined||'undefined' && test_ac_src!==undefined||'undefined' && test_sp_src!==undefined||'undefined'){
您可以(在云函数之外)声明一个函数,该函数检查变量是否未定义或为null,并按如下方式使用它:
admin.initializeApp();
firebase.initializeApp();
function testIsDefined(v) { // <- new function, returns true if not undefined and not null
return (typeof(v) != 'undefined' && v != null)
}
exports.takeValues = functions.database.ref('/users/{uid}/')
.onWrite((change, context) => {
var user_id = context.auth.uid;
var FB_access_token = change.after.val().Facebook_Access_Token;
var twitter_username = change.after.val().twitter_handle;
var insta_username = change.after.val().insta_handle;
var test_at_src = change.after.val().Test_Score.Arts;
var test_sp_src = change.after.val().Test_Score.Sports;
var test_ac_src = change.after.val().Test_Score.Academics;
if( testIsDefined(FB_access_token) && testIsDefined(twitter_username) && testIsDefined(insta_username) && ......) {
.....
}
.......