我正在尝试在我的 flutter 应用中使用firebase创建一个登录并注册系统。
主要登录将基于电话号码。
-对于注册,我打算要求:
在提交后,我将向电话号码发送OTP以验证并成功创建用户个人资料。
-对于登录,我将需要该电话号码,将发送OTP到电话号码,然后成功登录。
我已经看到以下基于电子邮件和密码的登录和注册:
createUserWithEmailAndPassword()
signInWithEmailAndPassword()
-目前,我发现了verifyPhoneNumber()
,但是,不知道如何完成注册。另外,如果未进行注册,它将如何验证?
请相应地指导我。
编辑: 我没有使用Firestore存储任何数据。为此,我有后端使用标头中发送的身份验证令牌来接收数据。
答案 0 :(得分:0)
尝试firebase_auth 0.15.3
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
演示
void _verifyPhoneNumber() async {
final PhoneVerificationCompleted verificationCompleted =
(AuthCredential phoneAuthCredential) {
_auth.signInWithCredential(phoneAuthCredential);
setState(() {
_message = 'Received phone auth credential: $phoneAuthCredential';
});
};
final PhoneVerificationFailed verificationFailed =
(AuthException authException) {
setState(() {
_message =
'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}';
});
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
widget._scaffold.showSnackBar(const SnackBar(
content: Text('Please check your phone for the verification code.'),
));
_verificationId = verificationId;
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
_verificationId = verificationId;
};
await _auth.verifyPhoneNumber(
phoneNumber: //put here phone number,
timeout: const Duration(seconds: 5),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
}
希望有帮助