【发布时间】:2015-12-29 01:31:35
【问题描述】:
我是 Angular 的新手,我正在关注在线的聊天应用教程。当我尝试使用电子邮件和密码注册时,我收到错误“Firebase.createUser failed: First argument must contain key "password"”。该应用程序尚未完成,我刚刚完成了身份验证部分。谷歌回答建议我更新到最新的 angularfire,我做了(1.1.3)。不知道该怎么办。
在 app.js 中注册状态:
.state('register', {
url: '/register',
templateUrl: 'auth/register.html',
controller:'AuthCtrl as authCtrl',
resolve:{
requireNoAuth: function($state,Auth){
return Auth.$requireAuth()
.then(function(auth){
$state.go('home');
},
function(error){
return;
});
}
}
})
authController.js
angular.module('chatApp')
.controller('AuthCtrl', function (Auth, $state) {
//Using 'Controller as syntax', instead of $scope, we use 'this' to make controller
var authCtrl = this;
//user object controller
authCtrl.user = {
email:'',
pass:''
};
//login object controller. Firebase provides functions. Using promises. ( either it's fufilled, or rejected)
authCtrl.login = function () {
Auth.authWithPassword(authCtrl.user)
// .then takes in 2 parameters( onSuccess, onFaliure)
//if successfull, go home
.then(function (auth) {
$state.go('home');
},
//if failed, set error in controller, so we can call it and display message later
function (error) {
authCtrl.error = error;
});
};
//registering user
authCtrl.register = function () {
Auth.$createUser(authCtrl.user)
// prompt user to login if successful
.then(function (user) {
authCtrl.login();
},
//else bring up error
function (error) {
authCtrl.error = error;
})
}
});
authFactory.js
angular.module('chatApp')
.factory('Auth',function($firebaseAuth,FirebaseUrl){
var declare= new Firebase(FirebaseUrl);
var auth=$firebaseAuth(declare);
return auth
});
【问题讨论】:
-
您是否尝试将字段 authCtrl.user { pass: ... } 重命名为 { password: }?
-
@JoaozitoPolo 哈哈,删除了错误!谢谢老兄,我太笨了。密码就像一个特定的关键字,为什么它不能与 pass 一起使用?现在每次注册都提示“指定的邮箱地址无效”。??
标签: javascript angularjs firebase angularfire