I want to link phone and email auth in a Flutter project using FirebaseAuth.
Steps are below:
auth = FirebaseAuth.instance;
Get user's phone number and send sms code using auth.verifyPhoneNumber
Get sms code input from user and send to
PhoneAuthCredential credential = PhoneAuthProvider.credential( verificationId: verificationId, smsCode: smsCode, );pass the 'credential' to email register page and combine with an authResult like this:
final UserCredential authResult = await _auth .createUserWithEmailAndPassword(email: email, password: password); await authResult.user.linkWithCredential(phoneCredential);
The thing is, I want to check if user's sms code input is valid or not before getting the email register page. The only way I've found to check this is put this credential to auth.signInWithCredential(credential). But I want to avoid this, because the other pages listen to onAuthChanged so that it can react if any sign-in or out occurs.
What would be the best way to solve this problem?
Thanks in advance.