Skip to content

Commit

Permalink
Exposes authWithPassword unauth and auth events
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Didron committed Sep 7, 2015
1 parent 9b04d01 commit c90638e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
46 changes: 40 additions & 6 deletions dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ return /******/ (function(modules) { // webpackBootstrap
}

if (typeof errorMsg !== 'undefined') {
_throwError(errorMsg, 'INVALID_URL');
_throwError(errorMsg, "INVALID_URL");
}
};

Expand All @@ -166,7 +166,7 @@ return /******/ (function(modules) { // webpackBootstrap
}

if (typeof errorMsg !== 'undefined') {
_throwError(errorMsg, 'INVALID_ENDPOINT');
_throwError(errorMsg, "INVALID_ENDPOINT");
}
};

Expand Down Expand Up @@ -198,15 +198,15 @@ return /******/ (function(modules) { // webpackBootstrap
} else if (!firebaseRefs[endpoint][invoker]) {
firebaseRefs[endpoint][invoker] = ref.ref();
} else {
_throwError('Endpoint (' + endpoint + ') already has listener ' + invoker, 'INVALID_ENDPOINT');
_throwError('Endpoint (' + endpoint + ') already has listener ' + invoker, "INVALID_ENDPOINT");
}
};

function _addListener(endpoint, invoker, options, ref) {
ref = _addQueries(ref, options.queries);
firebaseListeners[endpoint][invoker] = ref.on('value', function (snapshot) {
var data = snapshot.val();
data = data === null ? (options.asArray === true ? [] : {}) : data;
data = data === null ? options.asArray === true ? [] : {} : data;
if (invoker === 'listenTo') {
options.asArray === true ? options.then.call(options.context, _toArray(data)) : options.then.call(options.context, data);
} else if (invoker === 'syncState') {
Expand Down Expand Up @@ -305,9 +305,9 @@ return /******/ (function(modules) { // webpackBootstrap

function _removeBinding(refObj) {
_validateEndpoint(refObj.endpoint);
if (typeof firebaseRefs[refObj.endpoint][refObj.method] === 'undefined') {
if (typeof firebaseRefs[refObj.endpoint][refObj.method] === "undefined") {
var errorMsg = 'Unexpected value for endpoint. ' + refObj.endpoint + ' was either never bound or has already been unbound.';
_throwError(errorMsg, 'UNBOUND_ENDPOINT_VARIABLE');
_throwError(errorMsg, "UNBOUND_ENDPOINT_VARIABLE");
}
firebaseRefs[refObj.endpoint][refObj.method].off('value', firebaseListeners[refObj.endpoint][refObj.method]);
delete firebaseRefs[refObj.endpoint][refObj.method];
Expand All @@ -332,6 +332,28 @@ return /******/ (function(modules) { // webpackBootstrap
firebaseListeners = {};
};

function _authWithPassword(credentials, fn) {
var ref = new Firebase('' + baseUrl);
return ref.authWithPassword(credentials, function (error, authData) {
return fn(error, authData);
});
}

function _onAuth(fn) {
var ref = new Firebase('' + baseUrl);
return ref.onAuth(fn);
}

function _offAuth(fn) {
var ref = new Firebase('' + baseUrl);
return ref.offAuth(fn);
}

function _unauth() {
var ref = new Firebase('' + baseUrl);
return ref.unauth();
}

function init() {
return {
listenTo: function listenTo(endpoint, options) {
Expand All @@ -354,6 +376,18 @@ return /******/ (function(modules) { // webpackBootstrap
},
reset: function reset() {
_reset();
},
authWithPassword: function authWithPassword(credentials, fn) {
return _authWithPassword(credentials, fn);
},
onAuth: function onAuth(fn) {
return _onAuth(fn);
},
offAuth: function offAuth(fn) {
return _offAuth(fn);
},
unauth: function unauth(fn) {
return _unauth();
}
};
};
Expand Down
34 changes: 34 additions & 0 deletions src/rebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ module.exports = (function(){
firebaseListeners = {};
};

function _authWithPassword(credentials ,fn){
var ref = new Firebase(`${baseUrl}`);
return ref.authWithPassword(credentials, function(error, authData){
return fn(error, authData);
});
}

function _onAuth(fn){
var ref = new Firebase(`${baseUrl}`);
return ref.onAuth(fn);
}

function _offAuth(fn){
var ref = new Firebase(`${baseUrl}`);
return ref.offAuth(fn);
}

function _unauth(){
var ref = new Firebase(`${baseUrl}`);
return ref.unauth();
}

function init(){
return {
listenTo(endpoint, options){
Expand All @@ -296,6 +318,18 @@ module.exports = (function(){
},
reset(){
_reset();
},
authWithPassword(credentials, fn){
return _authWithPassword(credentials, fn);
},
onAuth(fn){
return _onAuth(fn);
},
offAuth(fn){
return _offAuth(fn);
},
unauth(fn){
return _unauth();
}
}
};
Expand Down

0 comments on commit c90638e

Please sign in to comment.