Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
makeRemoteRequest = async () => {
// console.log('makeRemoteRequest', Object.keys(Fire.shared));
if (!Fire.shared.uid) {
return;
}
if (this.state.refreshing) {
return;
}
const timeout = setTimeout(() => {
this.setState({ refreshing: false });
}, 5000);
this.setState({ refreshing: true });
dispatch.leaders.getPagedAsync({
start: this.lastKnownKey,
size: Settings.leaderPageSize,
callback: ({ cursor, noMore }) => {
clearTimeout(timeout);
this.setState({ noMore, refreshing: false });
this.lastKnownKey = cursor;
},
});
};
init = () => {
if (!Settings.isFirebaseEnabled) {
return;
}
firebase.initializeApp(Secret);
firebase.firestore().settings({ timestampsInSnapshots: true });
dispatch.user.observeAuth();
// DEBUG
if (!Settings.debug) {
dispatch.leaders.clear();
}
// dispatch.players.clear();
// dispatch.user.clear();
};
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
// TODO: Evan: Y tho...
dispatch.user.clear();
dispatch.user.signInAnonymously();
} else {
dispatch.user.getAsync();
dispatch.leaders.getAsync({ uid: user.uid });
}
});
},
} else {
const _data = doc.data();
const uid = doc.id;
data.push({
uid,
user: {
key: uid,
uid,
displayName: parseName(_data.displayName, _data.deviceName),
..._data,
},
});
}
});
console.log('Batch update', data.length, { data });
dispatch.leaders.batchUpdate(data);
const cursor = querySnapshot.docs[querySnapshot.docs.length - 1];
if (callback) callback({ data, cursor, noMore: data.length < size });
return;
} catch (error) {
console.error('Error getting documents: ', error);
}
if (callback) callback({});
},
getAsync: async ({ uid, callback }) => {
const nUser = {
rank: 999999,
displayName: _displayName,
photoURL: currentUser.photoURL || '',
score: 0,
timestamp: Date.now(),
};
ref.set(nUser);
if (callback) callback(nUser);
return;
}
console.log(`No document: leaders/${uid}`);
} else {
const user = doc.data();
console.log('got leader', user);
dispatch.leaders.update({ uid, user });
if (callback) callback(user);
return;
}
} catch ({ message }) {
console.log('Error: leaders.get', message);
alert(message);
}
if (callback) callback(null);
},
},
);
const user = {
rank: 999999,
displayName: _displayName,
score: 0,
timestamp: Date.now(),
};
if (currentUser.photoURL) {
user.photoURL = currentUser.photoURL;
}
ref.add(user);
dispatch.players.update({ uid, user });
if (callback) callback(user);
} else {
dispatch.leaders.getAsync({
uid,
callback: (user) => {
if (user) {
dispatch.players.update({ uid, user });
}
if (callback) callback(user);
},
});
}
} else {
const user = doc.data();
console.log('got player', user);
dispatch.players.update({ uid, user });
if (callback) callback(user);
}
} catch ({ message }) {