AngularFireAuth错误

时间:2018-08-17 02:22:43

标签: angular firebase firebase-authentication angularfire2 angularfire5

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

每次我将此方法称为当前用户更改为创建的用户。

我有以下Firebase数据库规则:

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

因此,如果我创建了一个Firebase身份验证用户,然后在当前的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 );
            });
        }

1 个答案:

答案 0 :(得分:0)

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}`);
          });