【问题标题】:Integrating Touch ID with Firebase Auth in React Native在 React Native 中将 Touch ID 与 Firebase Auth 集成
【发布时间】:2018-10-22 09:45:28
【问题描述】:
我是 React native 的新手,但我创建了一个使用 react-native-firebase 包(基于 https://github.com/faahmad/react-native-firebase-auth)的注册/登录,我想合并 touch id 以允许用户登录,但我无法在线找到任何示例(与 firebase 原生反应)。我查看了 react-native-fingerprint-scanner 和 react-native-touch-id 包,它们可以直接实现我只是不知道如何将 firebase auth 和 touch id 联系在一起。对此的任何帮助表示赞赏。
谢谢
【问题讨论】:
标签:
firebase
react-native
firebase-authentication
touch-id
【解决方案1】:
这只是一个想法,尚未实现为“实际代码”,但是......这是我如何处理它的两分钱:
用户注册后,您可以使用AsyncStorage、SQLite 或其他方式存储他们的电子邮件和密码。然后在用户的设置页面中添加Login with fingerprint 作为功能。从那里,一旦用户决定再次登录,您可以:
1- 使用react-native-fingerprint-scanner 给你的承诺。
2- 从您选择的数据库中获取电子邮件和密码。
3- 使用该数据通过 firebase 进行身份验证并登录。
它看起来像这样:
handleLogin() {
FingerprintScanner
.authenticate({ description: 'Scan your fingerprint to login' })
.then(() => {
const sql = "select email, password from user";
db.runQuery(sql, function(data) { // this is a made-up function
const { email, pasword } = data
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.then(() => /*navigate to main page once authenticated*/)
.catch(error => this.setState({ errorMessage: error.message
});
})
.catch(console.error);
}
还有改进的余地,但这应该适合您。希望能帮助到你。