0

我对 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 );
            });
        }
4

1 回答 1

0

After createUserWithEmailAndPassword() you need use the signInFirebaseWithEmailAndPassword method, like that

       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-08-17T03:30:45.700 回答