0

I have a problem to AngularFireAuth.auth.createUserWithEmailAndPassword()

Each time I call this method current user change to the created user.

I have firebase database rules like:

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

so if i create a firebase auth user and then i create an item on the current firebase database obviously is denied 'cause de new user does not have the correct permissions.

I have this code:

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 );
            });
        }
KENdi
  • 7,576
  • 2
  • 16
  • 31

1 Answers1

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}`);
          });
youDaily
  • 1,372
  • 13
  • 21