首页 > 解决方案 > 在 React Native 中将 Touch ID 与 Firebase Auth 集成

问题描述

我是 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 联系在一起。对此的任何帮助表示赞赏。

谢谢

标签: firebasereact-nativefirebase-authenticationtouch-id

解决方案


这只是一个想法,尚未实现为“实际代码”,但是......这是我如何处理它的两分钱:

用户注册后,您可以使用AsyncStorageSQLite或其他方式存储他们的电子邮件和密码。然后在用户的设置页面中添加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);
}

有改进的余地,但这应该适合你。希望能帮助到你。


推荐阅读