【问题标题】:AngularFireAuth errorAngularFireAuth 错误
【发布时间】:2019-01-24 00:53:49
【问题描述】:

我对 AngularFireAuth.auth.createUserWithEmailAndPassword() 有疑问

每次我调用此方法时,当前用户都会更改为创建的用户。

我有 Firebase 数据库规则,例如:

    {
      "rules": {
        ".read": "auth.uid != null",
        ".write": "auth.uid == '`<uid user>`'"
      }
   }

所以如果我创建了一个 firebase auth 用户,然后我在当前的 firebase 数据库上创建了一个项目,显然会被拒绝,因为新用户没有正确的权限。

我有这个代码:

this.afAuth.auth.createUserWithEmailAndPassword( email, 'password' )
            .then( () => {
                this.firebaselist.set( id ) , {
                    data: data
                }).then( () => console.log( 'user added' ) )
                .catch( ( error ) =>{
                    console.log(error);
                } );
            } )
            .catch(function(error) {
                var errorCode = error.code;
                var errorMessage = error.message;
                console.log( error );
            });
        }

【问题讨论】:

    标签: angular firebase firebase-authentication angularfire2 angularfire5


    【解决方案1】:

    createUserWithEmailAndPassword() 之后你需要使用signInFirebaseWithEmailAndPassword 方法,就像那样

           self.firebaseAuth
              .signInFirebaseWithEmailAndPassword(param.email, param.pw)
              .then(resAuth => {                
                console.log("Successfully authenticated with Firebase!");
              })
              .catch(err => {
                const errorCode = err.code;
                const errorMessage = err.message;
    
                console.error(`${errorCode} Could not log into Firebase: ${errorMessage}`);
              });
    

    【讨论】:

    • 好吧,我试试,你一直这样用吗?
    猜你喜欢
    • 2018-10-10
    • 2020-11-30
    • 2017-10-11
    • 2019-01-10
    • 1970-01-01
    • 2013-11-13
    • 2014-01-18
    • 2013-07-22
    • 1970-01-01
    相关资源
    最近更新 更多