在Firebase身份验证中,通常可以将其设为described here。
但是,对于Flutter,只有三种预制的链接方法,即 linkWithEmailAndPassword
, linkWithGoogleCredential
和 linkWithFacebookCredential
>。
我已经发现该in Flutter没有直接实现。
我想知道目前是否有任何方法可以实现这一目标。
答案 0 :(得分:2)
firebaseAuth = FirebaseAuth.instance;
您可以使用verifyPhoneNumber
发送验证短信,并从verificationID
回调中检索创建PhoneAuthCredential
所需的codeSent
:
firebaseAuth.verifyPhoneNumber(phoneNumber: ..., codeSent: (verificationId, [_]) async {
// you need to get the SMS code from the user before the next step, e.g. by using a TextField
// in this example that would be stored in [codeRetrieved]
(await firebaseAuth.currentUser()).linkWithCredential(
PhoneAuthProvider.getCredential(verificationId: verificationId, smsCode: codeRetrieved)
);
});
如果用户在Android上自动获得验证,则可以使用verificationCompleted
,它为您提供了预先配置的凭据:
firebaseAuth.verifyPhoneNumber(..., verificationCompleted: (credential) async {
(await firebaseAuth.currentUser()).linkWithCredential(credential);
});