在 Auth 状态下更改了 AngularFire

编程入门 行业动态 更新时间:2024-10-24 22:18:37
本文介绍了在 Auth 状态下更改了 AngularFire的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-22 11:02:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:改了   状态下   Auth   AngularFire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!