Reputation: 5111
I've been working with AngularFire .5 and Firebase (both of these I am getting from a Bower Install
.
I started by sifting through the Firereader code base, and have been working to update the methods. So far so good, and I think everything seems to be loading ok.
I am able to initialize $firebaseAuth
passing in my firebaseio.com
url. Page loads fine.
I am using requirejs to modularize everything, and bootstraping angular manually.
Where I seem to be struggling, is knowing which directives to load, and when, based on numerous samples and docs all being in various states of completion (I totally get that).
My initialization of the app looks like this -
define([
'angular',
'angular-route',
'ui-bootstrap',
'ui-bootstrap-tpls',
'./controllers/index',
'./directives/index',
'./filters/index',
'./services/index',
'Firebase',
'angularFire',
'Firebase-Auth-Client',
'Firebase-Simple-Login',
'underscore'
], function (angular) {
'use strict';
return angular.module('app', [
'app.controllers',
'app.directives',
'app.filters',
'app.services',
'ngRoute',
'ui.bootstrap',
'ui.bootstrap.tpls',
'firebase'
]);
});
Not sure if my requirejs deps need to be tweaked - like simple login or auth client require firebase? That could be part of this.
The other issue is, I'm still learning Angularjs, and it could just be a bone-head move on my part trying to get it all working.
I've created a service to handle all of the authentication (based on the Firebase example, but trying to work it from nothing to get the hang of it all).
The service looks like this -
services.factory('authManager', ['$rootScope', 'fbRef', '$firebaseAuth', function($rootScope, fbRef, $firebaseAuth) {
//authScopeUtil($rootScope);
$rootScope.auth = $firebaseAuth(fbRef(),{
'path' : '/'
});
$rootScope.auth = {
authenticated: false,
user: null,
name: null
};
// provide some convenience methods to log in and out
return {
login: function(providerId) {
//$firebaseAuth.login(providerId, {scope: 'email'});
console.log(providerId);
},
logout: function() {
$firebaseAuth.logout();
},
createUser: function(data) {
var email = data.email;
var password = data.password;
$firebaseAuth.createUser(email, password, function(error, user){
if (!error) {
console.log('User Id: ' + user.id + ', Email: ' + user.email);
}
})
}
};
}]);
fbRef looks like this -
services.factory('fbRef', ['fbUrl', 'Firebase', function(fbUrl, Firebase) {
// url can be an array or string
return function(url, limit) {
var ref = new Firebase(fbUrl(url));
if( limit ){
ref = ref.limit(limit);
}
return ref;
}
}]);
Maybe this needs to be new FirebaseSimpleLogin
?
When I run the code, I get the following error -
TypeError: Object function (ref, options) {
var auth = new AngularFireAuth($q, $t, $i, $rs, $l, ref, options);
return auth.construct();
} has no method 'createUser'
I don't know if I need $createUser, $firebaseAuth, AngularFireAuth, etc. So far, nothing seems to solve the error, and allow me to call the createUser()
function outline both here and here.
Sorry for being long winded (and possible really naive here) - just not sure where else to change things.
Upvotes: 1
Views: 788
Reputation: 7428
The expected usage for $firebaseAuth
is to create an instance of it and then call methods on that object:
var auth = $firebaseAuth(ref);
auth.$createUser(...);
Upvotes: 2