firebase can be enabled through config
This commit is contained in:
+2
-1
@@ -72,6 +72,7 @@
|
||||
},
|
||||
"FIREBASE": {
|
||||
"APP": "app-name",
|
||||
"SECRET": "secret"
|
||||
"SECRET": "secret",
|
||||
"ENABLED": "false"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
var Firebase = require('firebase');
|
||||
var nconf = require('nconf');
|
||||
var isProd = false //nconf.get('NODE_ENV') === 'production';
|
||||
var firebaseRef;
|
||||
var isProd = nconf.get('NODE_ENV') === 'production';
|
||||
var firebaseConfig = nconf.get('FIREBASE');
|
||||
|
||||
var firebaseRef;
|
||||
var isFirebaseEnabled = (nconf.get('NODE_ENV') === 'production') && (firebaseConfig.ENABLED === 'true');
|
||||
|
||||
// Setup
|
||||
if(isProd){
|
||||
if(isFirebaseEnabled){
|
||||
firebaseRef = new Firebase('https://' + firebaseConfig.APP + '.firebaseio.com');
|
||||
|
||||
// TODO what happens if an op is sent before client is authenticated?
|
||||
firebaseRef.authWithCustomToken(firebaseConfig.SECRET, function(err, authData){
|
||||
// TODO it's ok to kill the server here? what if FB is offline?
|
||||
if(err) throw new Error('Impossible to authenticate Firebase');
|
||||
@@ -17,7 +20,7 @@ if(isProd){
|
||||
var api = module.exports = {};
|
||||
|
||||
api.updateGroupData = function(group){
|
||||
if(!isProd) return;
|
||||
if(!isFirebaseEnabled) return;
|
||||
// TODO is throw ok? we don't have callbacks
|
||||
if(!group) throw new Error('group is required.');
|
||||
// Return in case of tavern (comparison working because we use string for _id)
|
||||
@@ -30,7 +33,7 @@ api.updateGroupData = function(group){
|
||||
};
|
||||
|
||||
api.addUserToGroup = function(groupId, userId){
|
||||
if(!isProd) return;
|
||||
if(!isFirebaseEnabled) return;
|
||||
if(!userId || !groupId) throw new Error('groupId, userId are required.');
|
||||
if(groupId === 'habitrpg') return;
|
||||
|
||||
@@ -42,7 +45,7 @@ api.addUserToGroup = function(groupId, userId){
|
||||
};
|
||||
|
||||
api.removeUserFromGroup = function(groupId, userId){
|
||||
if(!isProd) return;
|
||||
if(!isFirebaseEnabled) return;
|
||||
if(!userId || !groupId) throw new Error('groupId, userId are required.');
|
||||
if(groupId === 'habitrpg') return;
|
||||
|
||||
@@ -54,7 +57,7 @@ api.removeUserFromGroup = function(groupId, userId){
|
||||
};
|
||||
|
||||
api.deleteGroup = function(groupId){
|
||||
if(!isProd) return;
|
||||
if(!isFirebaseEnabled) return;
|
||||
if(!groupId) throw new Error('groupId is required.');
|
||||
if(groupId === 'habitrpg') return;
|
||||
|
||||
@@ -70,7 +73,7 @@ api.deleteGroup = function(groupId){
|
||||
// FIXME not really necessary as long as we only store room data,
|
||||
// as empty objects are automatically deleted
|
||||
api.deleteUser = function(userId){
|
||||
if(!isProd) return;
|
||||
if(!isFirebaseEnabled) return;
|
||||
if(!userId) throw new Error('userId is required.');
|
||||
|
||||
firebaseRef.child('users/' + userId)
|
||||
|
||||
Reference in New Issue
Block a user