phone authentication firebase code example
Example 1: phone authentication firebase flutter
Future<void> _submitPhoneNumber() async {
String phoneNumber = "+91 " + _phoneNumberController.text.toString().trim();
print(phoneNumber);
void verificationCompleted(AuthCredential phoneAuthCredential) {
print('verificationCompleted');
...
this._phoneAuthCredential = phoneAuthCredential;
print(phoneAuthCredential);
}
void verificationFailed(AuthException error) {
...
print(error);
}
void codeSent(String verificationId, [int code]) {
...
print('codeSent');
}
void codeAutoRetrievalTimeout(String verificationId) {
...
print('codeAutoRetrievalTimeout');
}
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(milliseconds: 10000),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
);
}
Example 2: how to verify sms token firebase
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key={FIREBASE_SERVER_KEY}
{
“idToken”: “eyJhbGciOiJEanNZspytaJL4wDZmu2OcwQujC360AJ_Q”
}
{
…,
“users”: [
{
…,
“phoneNumber”: “+351966666666”,
…
}
]
}