Phone

TerraCore v0

Login your user with phone number

Installation#

implement("vn.teko.android.auth:terra-auth:$version")

Enable phone login method in Terra Console#

Please contact us we will setup it for you

Usage#

You will need to implement an phone + otp login form yourself, then pass input data to TerraAuth for logging in.

Firstly, initialize phone login with OTP request. A successful call means an OTP is sent to your user, you can show the OTP form for user to enter.

You can also use this function for resending OTP.

// request OTP
val terraAuth = TerraAuth.getInstance(terraApp)
PhoneProvider.requestPhoneOtp(phoneNumber, terraAuth) { result: Result<Unit, Throwable> ->
when (result) {
is Result.Success -> // request successfully, show OTP form for user
is Result.Failure -> // handle failure OTP request
}
}

After user enters the OTP, you can now create the credential to login

// create the credential
val credential = PhoneProvider.getLoginCredential(phoneNumber, otp)
// login
TerraAuth.getInstance(terraApp).loginWithCredential(credential) { result: Result<Unit, Throwable> ->
when (result) {
is Result.Success -> // handle successful login
is Result.Failure -> // handle failed login
}
}

After logging in success, you now have the access_token. Please continue to Access Token Usage for usage guide.