Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
loadMessages(callback) {
this.messagesRef = firebase.database().ref("messages");
this.messagesRef.off();
const onReceive = data => {
const message = data.val();
callback({
_id: data.key,
text: message.text,
createdAt: new Date(message.createdAt),
user: {
_id: message.user._id,
name: message.user.name
}
});
};
this.messagesRef.limitToLast(20).on("child_added", onReceive);
}
// send the message to the Backend
return new Promise((resolve, reject) => {
const email = firebase.auth().currentUser.email;
firebase
.database()
.ref('users/' + formatEmail(email))
.update(user);
dispatch(receiveAuth(user));
resolve();
}).catch(err => {
console.warn('Error catched');
componentWillMount() {
const dbRef = firebase.database().ref(this.props.path);
console.log(`Installing handler on path: ${this.props.path}`);
dbRef.on('value', this.handleValueChange);
this._setHandler = true;
}
const emitter = (data: DataSnapshot) => {
if (data.toJSON()) {
emit(data.toJSON())
}
}
const cancel = () => {
firebase
.database()
.ref(REQUEST_DB)
.orderByChild(REQUESTEE_ADDRESS)
.equalTo(address)
.off(VALUE, emitter)
}
firebase
.database()
.ref(REQUEST_DB)
.orderByChild(REQUESTEE_ADDRESS)
.equalTo(address)
.on(VALUE, emitter, errorCallback)
return cancel
})
}
function* updatePaymentRequestStatus({ id, status }: UpdatePaymentRequestStatusAction) {
try {
Logger.debug(TAG, 'Updating payment request', id, status)
yield call(firebase.database().ref(`${REQUEST_DB}/${id}`).update, { status })
Logger.debug(TAG, 'Payment request status updated', id)
} catch (error) {
Logger.error(TAG, `Error while updating payment request ${id} status`, error)
}
}
return new Promise(function(resolve, reject) {
firebase
.database()
.ref('users/')
.orderByChild('email')
.equalTo(value)
.on('value', function(snapshot) {
if (snapshot.val()) {
snapshot.forEach(function(data) {
let user = [
{
name: data.val().name,
picture: data.val().picture,
email: data.val().email
}
];
resolve(user);
});
export async function setUserLanguage(address: string, language: string) {
try {
Logger.info(TAG, `Setting language selection for user ${address}`)
const regRef = firebase.database().ref('registrations')
await regRef.child(address).update({ language })
Logger.info(TAG, 'User Language synced successfully', language)
} catch (error) {
Logger.error(TAG, 'Failed to sync user language selection', error)
throw error
}
}
constructor() {
this.database = firebase.database()
}
getTimestamp() {
return firebase.database().getServerTime();
},