Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return userRef.once('value').then(userSnap => {
if (userSnap.val() || userSnap.hasChild('sessions')) {
console.error('User account already exists.')
return Promise.reject(userSnap.val())
}
userObj.createdAt = Firebase.ServerValue.TIMESTAMP
// [TODO] Add check for email before using it as priority
return userRef.setWithPriority(userObj, email).then(_ => userObj)
})
})
import Firebase from "firebase";
import config from "../config";
var firebase = new Firebase(config.firebase);
firebase.TIMESTAMP = Firebase.ServerValue.TIMESTAMP;
// For debugging
window.firebase = firebase;
export default firebase;
export default function create(firebaseUrl) {
const firebase = new Firebase(firebaseUrl);
return {
TIMESTAMP: Firebase.ServerValue.TIMESTAMP,
root: firebase,
// const options = {
// scope: {
// facebook: 'email,user_friends',
// google: 'email',
// twitter: '' // email must be requested ad hoc
// }[provider]
// }
authWithOAuth(provider, options) {
return promisify(onComplete => {
// https://www.firebase.com/docs/web/guide/user-auth.html#section-popups
firebase.authWithOAuthPopup(provider, (error, authData) => {
if (error && error.code === 'TRANSPORT_UNAVAILABLE') {
firebase.authWithOAuthRedirect(provider, onComplete, options);
}, function(err, data) {
if(err) console.log('s3.putObject error', err);
firebase_root.child('screencast/last_updated').set(Firebase.ServerValue.TIMESTAMP);
});
});
firebase.authWithOAuthPopup('github', function (err, auth) {
if (err) {
console.log('Login failed:', err)
alert('Login failed.\n\n' + err.message)
}
if (auth) {
firebase.child('users').child(auth.uid).update({
updated_at: Firebase.ServerValue.TIMESTAMP,
last_auth: auth
})
}
})
}
return new Promise(function(resolve, reject) {
var date = new Date();
var fmtDate =
date.getFullYear() + '-' +
doubleDigitDate(date.getMonth() + 1) + '-' +
doubleDigitDate(date.getDate()) + ' ';
fmtDate +=
date.getHours() + ':' +
doubleDigitDate(date.getMinutes()) + ':' +
doubleDigitDate(date.getSeconds());
newMarkerKey = projects.push({timestamp: Firebase.ServerValue.TIMESTAMP, clientTime: fmtDate}, function(err) {
if (err) return reject(err);
resolve(projects);
}).key();
});
}
this.onAuth((authData) => {
if (!authData) {
endedRef.set(Firebase.ServerValue.TIMESTAMP);
currentSesh.remove();
onlineRef.remove();
}
});
}
publishScore(score: ISimonScoreInfo) {
this.fbRef.child('games').push(Object.assign({
date: Firebase.ServerValue.TIMESTAMP
}, score));
}
}
index.saveObject(firebaseObject).then(function() {
ref.child('last_index').set(Firebase.ServerValue.TIMESTAMP).then(context.done);
}).catch(context.done);
});
getUserByPhone(from, function(user){
if (!user) return;
var newMessage = {}
newMessage.message = message;
newMessage.name = user.name;
newMessage.userId = user.id;
newMessage.type = "default";
newMessage.timestamp = Firebase.ServerValue.TIMESTAMP;
var newMessageRef = roomRef.push();
newMessageRef.setWithPriority(newMessage, Firebase.ServerValue.TIMESTAMP);
});
});