0

I am using ionic 3 and firebase authentication using facebook. The facebook does not return email id if user did not provided one while signup or did not verify it at all.

Our system mandates providing of email id. So, as a fall back we prompt user to provide the email id. As we let user manually provide the email id at this step so there is a need to verify it.

It seems firebase auth sendEmailVerifcation required the email id already in the auth. As our case is specifically handling when this is missing so how can we use this feature to validate the email id?

Any other ideas are welcome too to handle it. It is a critical blocker for us as people are misusing our reward system by providing fake email ids.

I have looked into the sendEmailVerification api but it does not seem to accept any parameter to manually pass the email id.

constructor(public navCtrl: NavController, 
              public navParams: NavParams,
              private afAuth: AngularFireAuth,
              private fb: Facebook, 
              private platform: Platform,
              private core:CoreProvider,
              public viewCtrl: ViewController,
              private ddlSvc: DoodleDataProvider,
              private alertCtrl:AlertController,
              private toastCtrl: ToastController) {
                
                //block back button on android
                platform.registerBackButtonAction(() => {
                            
                },1);

                afAuth.authState.subscribe(user => {
                  console.log("auth subscription finished: with user:" + JSON.stringify(user))

                  //go back if user could not be retrieved or manual logout is set to true
                  if (!user || core.manualLogout == true) {   
                    return;
                  }

                  user.sendEmailVerfication() //problem here when email is null
                  console.log("initializing user")
                  this.createUser(user.uid)
                });
  }
4
  • How about also creating an email+password account for them, and then linking the email+password and the Facebook accounts? After doing that, you can use sendEmailVerfication to send the verification message. Commented Jan 1, 2019 at 22:09
  • Well our client app which is ionic 3 based is a bakery app and we wanted to keep things simplest in terms of user login and accounts. so we loved the idea of using one click login with facebook. Now replacing it with a requirement to ask email plus password is something customer wont be happy. is there a work around way like creating account with email and password using provided email plus default password in the background and then send verification link? basically we need to verify emails only when fb does not give it to us. and we want to keep user experience the same. Commented Jan 1, 2019 at 23:47
  • You could generate a random password. I would not use a default password, since that would mean anyone who knows the password can log into each account. Commented Jan 2, 2019 at 1:54
  • well i understand the risk of a default password. but my intention is to use this email + pwd mechanism just to be able to use sendEmailVerification link in certain situations. I always want to force users to login using facebook. Do you think that can work? Commented Jan 2, 2019 at 1:59

2 Answers 2

2

Email verification is only for users who sign up with email/password authentication. The purpose is to validate that the user gave a valid email address at the time they signed up. You typically want to use email verification after you sign in the user with firebase.auth().createUserWithEmailAndPassword().

Email verification is not available for other authentication providers (such as Facebook), since they have their own way to managing their users' email addresses.

Sign up to request clarification or add additional context in comments.

3 Comments

can i workaround some on with a default password and user provided email? basically my need to verify is only when fb does not return me an email. So in those cases i need a way to send verification email. But then for all the users the login experience need to be the same that is using facebook sign.
No. As I said, email verification is only for email/password auth.
FWIW I've got email verification working in Firebase for other non-Google providers like Microsoft, it's not just limited to email/password auth.
0

As you noted, sendEmailVerifcation works only for the email that's configured in the auth user object, you can't send an email verification to a custom email.

What you can do especially in the case the email was originally null, is to update the auth user email with the email address you prompted them to input, before sending the verification email:

import { getAuth, updateEmail, sendEmailVerification } from "firebase/auth"

const auth = getAuth()

updateEmail(auth.currentUser, "[email protected]").then(() => {
  return sendEmailVerification(auth.currentUser)
}).catch(err => {
  // ...
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.