Firebase Phone Authentication

The Firebase Authentication Component can be used to authenticate users using their Phone Number. This Guide shows you how to implement Firebase Phone Authentication in your Apps made with Niotron.

If you haven’t implemented Firebase Core in your app. Check out this Guide to Know how to implement Firebase Core.

Initialization
#
  • Create a Global Variable to store the VerificationId from Firebase Phone Auth. This will be used later in order to manually verify user-entered OTP

  • Initialize the Firebase Auth Component. This can be done inside the Screen1 Initialize Event

In case Firebase Auth Fails to Initialize this event will be called. The error message can be used to debug the error

Sending The OTP #

In Order to Authenticate the user, an OTP has to be sent to the user. This is a one-time procedure and doing this the second time would instantly call the SMS verified Event as the user is already Verified.

phoneNumber: The Users Number to verify.
timeout: Timeout in seconds (60 – 120)

 

Verification SMS Sent Event

This event is called when the SMS is sent Successfully. This event returns the verificationId which has to be used in case of manual OTP Verification

returns:
verificationId: 
this has to be used in creating the Phone Auth Credential Used to Manually verify the user.

Verification SMS Timeout

This event is called when the Timeout value is reached. OTP Cannot be verified after this event is called.

Verifying The OTP #

The OTP Is Read when the user receives the SMS. In case the SMS is not read automatically manual verification is also possible.

SMS Verified Event

This event is called when the SMS is verified Automatically or that the user is already verified and it’s not required to send an OTP to the user.

returns:
phoneAuthCredentials: 
used in the  SignInWithPhone Function

SMS Verification Failed

This event is called when it fails to verify the SMS

returns:
errorMessage: error message as to what went wrong

Manually Verifying the OTP #

The Phone Auth Credential can be created manually in order to pass it to the SignInWithPhone Function

 

Sign In with Phone #

The SignInWithPhone Function can be used to Sign In the User.

The SignInWithPhone Function can be used inside the SmsVerified Event and pass the phoneAuthCredentails from the event or can be done manually using the CreatePhoneAuthCredential Function

PhoneSignInSuccessful

This event is called when Phone sign-in is successful

PhoneSignInFailed

This Event is called when Phone Sign In Fails

returns:
errorMessage: error message as to what went wrong.

Powered by BetterDocs