3

Is there a way of using "createUserWithEmailAndPassword" ? The reason I'm asking is because I want that the email gets verified before the user can logIn.

firebase.auth().createUserWithEmailAndPassword(mailId, password).then(function(data){
            console.log("user created");
firebase.auth().currentUser.sendEmailVerification().then(function() {
            console.log("verification email send");
            })
        }).catch(function(error) {
   console.log("error.message");
 })

This code signin user automatically and send the verification mail to user. Is there any way to verify email first than signIn.

KENdi
  • 7,576
  • 2
  • 16
  • 31
  • Please format it properly – eddyP23 Jul 18 '17 at 07:06
  • Simplest workaround would be to call `signOut` in the `then` handler (according to the [documentation](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword) the user will always be signed in after successful account creation) – UnholySheep Jul 18 '17 at 07:10

1 Answers1

2

You can't prevent user with an unverified email address from signing in. That's simply not how Firebase Authentication works: if the user knows the credentials needed to sign in, they've proven who they are and are signed in.

What you can do is prevent them from accessing specific resources, such as the Firebase Database. In fact, my answer to this question shows how to do that (and limit access to users from a specific email domain): How do I lock down Firebase Database to any user from a specific (email) domain?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807