问题描述
限时送ChatGPT账号..尝试使用 firebase 对用户进行身份验证.使用 firebase 2.xx 启动我的应用程序,但即使在升级到 Firebase 3.xx 后,抛出错误onAuthStateChanged 不是函数".
这就是我的登录功能的样子-
.controller('HomeCtrl', ['$scope','$location','CommonProp','$firebaseAuth', '$firebaseObject',function($scope,$location,CommonProp,$firebaseAuth,$firebaseObject) {var firebaseObj = $firebaseObject(rootRef);var loginObj = $firebaseAuth(firebaseObj);$scope.SignIn = 函数($scope,用户){event.preventDefault();//防止表单刷新var 用户名 = user.email;var 密码 = 用户名.密码;loginObj.$signInWithEmailAndPassword({电子邮件:用户名,密码:密码}).then(功能(用户){//成功回调console.log('认证成功');$location.path("/欢迎");CommonProp.setUser(user.password.email);}, 函数(错误){//失败回调控制台日志(错误);});}}]);
解决方案 您的问题是您正在将 $firebaseObject
传递给 $firebaseAuth()
.
因此,请确保您正在初始化您的 [$firebaseAuth][1]
对象,如下所示,然后您的代码应该可以正常工作.
var loginObj = $firebaseAuth();
正在使用 jsFiddle 进行演示.
您可以在此处查看 AngularFire2 的文档>
Trying to authenticate an user using firebase. Started my app using firebase 2.xx but even after upgrading to Firebase 3.xx, throwing error "onAuthStateChanged is not a function".
This is how my login function looks like-
.controller('HomeCtrl', ['$scope','$location','CommonProp','$firebaseAuth', '$firebaseObject',function($scope,$location,CommonProp,$firebaseAuth,$firebaseObject) {
var firebaseObj = $firebaseObject(rootRef);
var loginObj = $firebaseAuth(firebaseObj);
$scope.SignIn = function($scope, user) {
event.preventDefault(); // To prevent form refresh
var username = user.email;
var password = user.password;
loginObj.$signInWithEmailAndPassword({
email: username,
password: password
})
.then(function(user) {
// Success callback
console.log('Authentication successful');
$location.path("/welcome");
CommonProp.setUser(user.password.email);
}, function(error) {
// Failure callback
console.log(error);
});
}
}]);
解决方案
Your problem is that you are passing a $firebaseObject
to $firebaseAuth()
.
So make sure you are initializing your [$firebaseAuth][1]
object like the following and then your code should work properly.
var loginObj = $firebaseAuth();
Working jsFiddle for demonstrating.
You can check here the documentation for AngularFire2
这篇关于在 Auth 状态下更改了 AngularFire的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论