I am new to using Firebase
and Flutter
. While doing phone number authentication
on firebase i’m getting Internal server error
message. Please help.
com.example.shubh_chintak
is my package name
I/zzh (18073): ForceRecaptchaFlow from phoneAuthOptions = false, ForceRecaptchaFlow from firebaseSettings = false
I/PlayCore(18073): UID: [10405] PID: [18073] IntegrityService : requestIntegrityToken(IntegrityTokenRequest{nonce=1J4FG6Jr_wQLusX84KtIkX62iH537b731LPs_mt3i2g, cloudProjectNumber=551503664846})
I/PlayCore(18073): UID: [10405] PID: [18073] IntegrityService : Initiate binding to the service.
I/PlayCore(18073): UID: [10405] PID: [18073] IntegrityService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.integrityservice.IntegrityService})
I/PlayCore(18073): UID: [10405] PID: [18073] IntegrityService : linkToDeath
I/PlayCore(18073): UID: [10405] PID: [18073] OnRequestIntegrityTokenCallback : onRequestIntegrityToken
I/PlayCore(18073): UID: [10405] PID: [18073] IntegrityService : Unbind from service.
W/System (18073): Ignoring header X-Firebase-Locale because its value was null.
W/BpBinder(18073): Slow Binder: BpBinder transact took 290 ms, interface=com.google.android.gms.auth.api.phone.internal.ISmsRetrieverApiService, code=1 oneway=false
E/FirebaseAuth(18073): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Internal error encountered.
D/FirebaseAuth(18073): Invoking original failure callbacks after phone verification failure for +916394994875, error - An internal error has occurred. [ Internal error encountered. ]
I’m using following approach to authenticate with phone.
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:shubh_chintak/ShubhChintak/Buyer/BuyerCreateAccount.dart';
import 'package:shubh_chintak/ShubhChintak/Buyer/BuyerMainPage/BuyerMainPage.dart';
import 'package:shubh_chintak/ShubhChintak/constants.dart';
import 'package:shubh_chintak/ShubhChintak/reusableWidget.dart';
import 'package:shubh_chintak/ShubhChintakPostAPI/ShubhChintakHttp/ReturnBuyerIdHttp.dart';
class BuyerLoginPage extends StatefulWidget {
static String? buyer_id1 = _BuyerLoginPageState.buyer_id;
const BuyerLoginPage({Key? key}) : super(key: key);
@override
State<BuyerLoginPage> createState() => _BuyerLoginPageState();
}
class _BuyerLoginPageState extends State<BuyerLoginPage> {
final FirebaseAuth auth = FirebaseAuth.instance;
final _formKey = GlobalKey<FormState>();
String? useBuyerId;
static String? buyer_id;
final TextEditingController _bPhoneController = TextEditingController();
final TextEditingController _otpController = TextEditingController();
@override
Widget build(BuildContext context) {
var height = MediaQuery.of(context).size.height;
var width = MediaQuery.of(context).size.width;
var devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
return Scaffold(
body: Form(
key: _formKey,
child: SizedBox(
height: double.infinity,
width: double.infinity,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(
height: height * 0.25,
),
reusableLocaleText(
"login", devicePixelRatio * 12, TextAlign.center),
SizedBox(
height: height * 0.02,
),
SizedBox(
height: height * 0.32,
width: width * 0.8,
child: Card(
shadowColor: kPrimaryColor,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(devicePixelRatio * 10),
side: const BorderSide(color: kPrimaryColor)),
child: Container(
padding: EdgeInsets.fromLTRB(
width * 0.08,
height * 0.03,
width * 0.08,
height * 0.02,
),
child: Column(
children: <Widget>[
reusableTextFormField(
context,
"phone",
Icons.phone_android_sharp,
true,
true,
false,
false,
false,
false,
_bPhoneController,
),
SizedBox(
height: height * 0.05,
),
reusableElevatedButton(
context,
"sendotp",
25,
height * 0.055,
width * 0.8,
() async {
if (_bPhoneController.text.isEmpty) {
reusableSnackBar(
context,
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
devicePixelRatio * 10),
),
SnackBarBehavior.floating,
reusableLocaleText("pleaseenterphonenumber",
15, TextAlign.center),
);
} else if (_bPhoneController.text.length < 10 ||
_bPhoneController.text
.startsWith(0.toString())) {
reusableSnackBar(
context,
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
devicePixelRatio * 10),
),
SnackBarBehavior.floating,
reusableLocaleText(
"pleaseentervalidphonenumber",
15,
TextAlign.center),
);
} else {
FocusNode currentFocus = FocusScope.of(context);
if (currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
if (_formKey.currentState!.validate()) {
ReturnBuyerIdHttp returnBuyerLoginId =
ReturnBuyerIdHttp();
useBuyerId = await returnBuyerLoginId
.returnBuyerID(_bPhoneController.text);
buyer_id = returnBuyerLoginId.storeBuyerId;
if (returnBuyerLoginId.storeBuyerIdStatus ==
"Success") {
await FirebaseAuth.instance
.verifyPhoneNumber(
phoneNumber:
'+91${_bPhoneController.text}',
verificationCompleted:
(PhoneAuthCredential credential) {},
verificationFailed:
(FirebaseAuthException e) {},
codeSent: (String verificationId,
int? resendToken) {
try {
sendOTPAlertDialogBox(
context,
"enterotpsendonyourregisteredphone",
_otpController,
() async {
try {
// Create a PhoneAuthCredential with the code
PhoneAuthCredential credential =
PhoneAuthProvider.credential(
verificationId:
verificationId,
smsCode:
_otpController.text);
// Sign the user in (or link) with the credential
await auth.signInWithCredential(
credential);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const BuyerMainPage(),
),
);
} catch (exception) {
reusableSnackBar(
context,
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
devicePixelRatio *
10),
),
SnackBarBehavior.floating,
reusableLocaleText(
"pleaseentervalidotp",
15,
TextAlign.center),
);
}
},
"ok",
() {},
"resendotp",
);
}
on Exception catch (exception) {
reusableSnackBar(
context,
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
devicePixelRatio *
10),
),
SnackBarBehavior.floating,
reusableLocaleText(
exception.toString(),
15,
TextAlign.center),
);
}
},
codeAutoRetrievalTimeout:
(String verificationId) {},
);
} else {
reusableSnackBar(
context,
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
devicePixelRatio * 10),
),
SnackBarBehavior.floating,
reusableLocaleText(
"Invalidlogincredntials",
15,
TextAlign.center),
);
}
}
}
},
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
reusableLocaleText(
"don'thaveaccount?",
devicePixelRatio * 5,
TextAlign.center,
),
reusableTextButton(
context,
"create",
() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
const BuyerCreateAccount(),
),
);
},
)
],
)
],
),
),
),
),
],
),
),
),
),
);
}
}
2
Answers
There is issue with the firebase_core package version 2.9.0. downgrade it to 2.8.0 .This will resolve the issue
Downgraded all the way;
Also some weird error had to add
firebase_core_platform_interface: 4.5.1
underdev_dependencies
: