Bhawna Saroha
Bhawna Saroha

Reputation: 633

How to do OTP authentication in Flutter?

I am working on an app which uses Firebase as its backend. Currently, the registration process is set up with google email address and on the next screen, the user is prompted to enter their mobile number.

In the next step, the user gets an OTP sent to their phone which he then enters to complete the verify their phone number. I checked the phone authentication provided by Firebase but in my case user authentication is already getting handled on the first step with user's Google email address.

I have made this work on Android using this package: sms_maintained

But this doesn't work in iOS. Please suggest a way to make it work on both iOS and Android. Thank you for your time.

Upvotes: 1

Views: 5421

Answers (1)

Alok
Alok

Reputation: 8988

As a cleaner approach, I would suggest reading on this: MSG91 OTP API.

PLEASE NOTE: This will work on Android and iOS, since it a functional API, which requires calling and getting things done :)

I will tell you about this in a more vivid way:

  1. This is an API which will help you send the OTP using send API
  2. It also helps you verify the OTP after which you can go forward

Now, how you can do this:

>>> Make an account, and get your AUTH_KEYS which is necessary to get the API working
>>> After that, in your Dart app, generate your Random 4 or max supported digit OTP
>>> When you hit your button, or page which verifies the OTP, Send the OTP generated to the MSG91 Send API
>>> It will send you the OTP via SMS
>>> Use it to Verify, using Verify API
>>> Use the response coming from the API, to go back or show error
>>> And you're done

Make sure you read upon http, a flutter package, that allows you to call APIs. I hope that makes sense to you, and help you achieve what you want.

EXAMPLE: The best example I can give is myself only. I have already used this in my app, and it works like charm. It is functional, and I have not registered any problem till now.

Upvotes: 1

Related Questions