3
votes

After registering a new user with email and password using firebase flutter. Is there any way to verify his phone number without a firebase phone authentication so the same user will not be registered with email/password and phone number (I want to register him once using his email and password and verify his phone number)?

2

2 Answers

5
votes

You can try flutter_otp package I think it's the best option,

You can visit https://pub.dev/packages/flutter_otp for more info,

try the bellow example

import 'package:flutter/material.dart';
import 'package:flutter_otp/flutter_otp.dart';

// Now instantiate FlutterOtp class in order to call sendOtp function
FlutterOtp otp = FlutterOtp();
class SendOtp extends StatelessWidget {
   String phoneNumber = "93XXXXXXXX"; //enter your 10 digit number
   int minNumber = 1000;
   int maxNumber = 6000;
   String countryCode ="+91"; // give your country code if not it will take +1 as default


 @override
 Widget build(BuildContext context) {
   return Scaffold(
    appBar: AppBar(title: Text("send otp using flutter_otp ")),
    body: Container(
      child: Center(
        child: RaisedButton(
         child: Text("Send"),
         onPressed: () {
           // call sentOtp function and pass the parameters

        otp.sendOtp(phoneNumber, 'OTP is : pass the generated otp here ',
            minNumber, maxNumber, countryCode);
      },
    )),
  ),
);

} }

4
votes

I think you could try this package: https://pub.dev/packages/flutter_otp
and there are also a lot of websites that providers OTP SMS Services.

Tip: You can even use Firebase Auth since it also suits your case.

In firebase, you can just link (something like merge) the accounts that are created with Email and Phone using like this emailUser.getCurrentUser().linkWithCredential(phoneUserCredential)
In this case, your app will consist of one user with that Email and Phone.
Additional Benefit is that you don't want to store phone numbers in a separate database.
After linking both the accounts, you can just simply use user.displayName and user.phoneNumber to fetch your Email and Phone.

Refer:
https://firebase.google.com/docs/auth/android/account-linking
https://firebase.google.com/docs/auth/web/account-linking