我正在尝试使用firebaseAuth进行用户身份验证,以便在我的网络应用上登录和注册,但我不知道为什么寄存器和登录按钮没有响应。鉴于我仍处于使用firebase的学习曲线上,这可能并不令人惊讶。所以我有以下AuthService和AuthController代码:
AuthService:
angular.module('directiveAngularApp')
.service('Auth', function($firebaseAuth, FIREBASE_URL, $rootScope) {
var ref = new Firebase(FIREBASE_URL+'/users');
var auth = $firebaseAuth(ref);
var Auth = {
register: function (user) {
return auth.$createUser(user.email, user.password, function(error) {
if (error === null) {
console.log('user created successfully')
} else {
console.log('error in creating users: ' + error);
}
});
}, //register
login: function (user) {
return auth.$authWithPassword({
email: user.email,
password: user.password},
function(error, userData){
if (error) {
console.log('login failed');
} else {
console.log('Authentication successful: ' + userData);
}
});
}, //login
logout: function () {
auth.$logout();
}
};
return Auth;
});
AuthController:
angular.module('directiveAngularApp')
.controller('AuthCtrl', function($scope, $location, Auth){
$scope.login = function() {
console.log('in the login function');
Auth.login($scope.user).then(function() {
console.log('in the promise after login');
$location.path('/');
})
};
$scope.register = function() {
Auth.register($scope.user).then(function() {
return Auth.login($scope.user).then(function() {
console.log('promise called: register successful');
$location.path('/');
});
});
};
});
在网络表单中,我将以下两个字段设置为ng-models:
ng-model="user.email"
ng-model="user.password"
登录按钮与login()函数相关联,注册按钮链接到上面AuthController
中的register()函数。但是,当我点击“登录”或“注册”按钮时,没有响应。
答案 0 :(得分:0)
CreateUser将对象作为新API的参数
AUTH $的createUser(用户);
https://www.firebase.com/docs/web/api/firebase/createuser.html