簡體   English   中英

在React Native中將Touch ID與Firebase Auth集成

[英]Integrating Touch ID with Firebase Auth in React Native

我是React Native的新手,但是我創建了一個使用react-native-firebase軟件包(基於https://github.com/faahmad/react-native-firebase-auth )的注冊/登錄,我想合並觸摸ID來允許用戶登錄,但我無法在線找到任何示例(與Firebase結合使用)。 我看了一下可以直接實現的包react-native-fingerprint-scanner和react-native-touch-id,我只是不知道如何將Firebase auth和touch 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);
}

有待改進的地方,但這應該對您有用。 希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM