反应本地Firebase电话身份验证

时间:2019-08-30 17:23:54

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

我正在尝试使用expo和firebase身份验证构建一个React Native应用程序。电子邮件/密码身份验证工作正常,但是由于applicationVerifier,电话号码身份验证失败。 我尝试使用“ react-native-firebase”,但这也无法正常工作并给出错误。

[错误:仅在具有DOM支持的浏览器HTTP / HTTPS环境中支持RecaptchaVerifier。]

谢谢。

1 个答案:

答案 0 :(得分:0)

您需要制作.html文件并放入以下代码。

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>Entering captcha</title>
</head>
<body>
    <p style="text-align: center; font-size: 1.2em;">Please, enter captcha for continue<p/>
    <button id="continue-btn" style="display:none">Continue to app</button>

    <script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-auth.js"></script>
    <script>
      // Initialize Firebase
      var config = {
        apiKey: "AIzaSyCy6HyqIV5Q_A5lllIxZgePSmKq-Q8eqiw",
      authDomain: "onsignledemo.firebaseapp.com",
      databaseURL: "https://onsignledemo.firebaseio.com",
      projectId: "onsignledemo",
      storageBucket: "onsignledemo.appspot.com",
      messagingSenderId: "223114260821"
      };
      firebase.initializeApp(config);
    </script>    <script>
        function getToken(callback) {
            var container = document.createElement('div');
            container.id = 'captcha';
            document.body.appendChild(container);
            var captcha = new firebase.auth.RecaptchaVerifier('captcha', {
                'size': 'normal',
                'callback': function(token) {
                    callback(token);
                },
                'expired-callback': function() {
                    callback('');
                }
            });
            captcha.render().then(function() {
                captcha.verify();
            });
        }
        function sendTokenToApp(token) {
            var baseUri = decodeURIComponent(location.search.replace(/^\?appurl\=/, ''));
            const finalUrl = location.href = baseUri + '/?token=' + encodeURIComponent(token);
            const continueBtn = document.querySelector('#continue-btn');
            console.log(finalUrl);
            // continueBtn.onclick = (event)=>{
            //     window.open(finalUrl,'_blank')
            // }
            continueBtn.style.display = "block";
        }
        document.addEventListener('DOMContentLoaded', function() {
            getToken(sendTokenToApp);
        });
    </script>
</body>
</html>

将此文件放入您正在运行的服务器中,然后将您的URL加载到本机Webview中,然后再发送确认代码,并在验证此验证码后发送确认代码...