如何在react-native-firebase中的Firebase Auth signInWithPhoneNumber上获取验证回调?

时间:2019-01-27 16:30:07

标签: android firebase react-native firebase-authentication react-native-android

我正在我的本机应用程序中试用Firebase auth signInWithPhoneNumber。在https://rnfirebase.io/docs/master/auth/phone-auth之后。 但是在

firebase.auth().signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
  console.log(confirmResult)
}).catch(error => {
  console.log(error)
});

confirmResults没有确认方法。

ConfirmationResult {_auth: Auth {_app: App, _customUrlOrRegion: undefined, namespace: "auth", _user: null, _settings: null, …}
_verificationId: "AM5PThBgtChKnxaZPAnPE_9zR_4qd1p2YchqZLNexlWtTiBxkUhEoOd79z0oujNP9pYrs9rgUbTsluCnlsqFjJCdbv83d89vg9LhZXJWbsnTB6w8lmxn00OqVe8S_Qc3Pfnw2qHMgZzV"
verificationId: (...)
__proto__: Object

我在做什么错了?

1 个答案:

答案 0 :(得分:1)

看来您做对了所有事情。控制台输出显示您正在接收ConfirmationResult类的实例。

在类的实例上执行console.log()时,不会显示该类的方法。

如果您将实例存储在变量中,然后在该类的存储实例上调用confirmResult.confirm(),则将调用confirm方法,并验证提供给confirm()的代码。

有关该类的更多详细信息,请参见RNFirebase电话验证Docs中的ConfirmationResult。