2016-03-05 45 views
1

我有一个简单的自定义登录页面,使用Firebase。基本上有一个管理页面,JavaScript正在检查当前用户是否通过身份验证。如果没有,它将被重定向到一个登录页面,在认证后将返回到原来的管理员的东西。无法使用Internet Explorer 11登录到Firebase

这是检查验证的脚本:

 <script type="text/javascript"> 
var ref = new Firebase("firebase.linkishere.com ?>");  

var authData = ref.getAuth(); 
if (authData) { 
    console.log("User is authenticated!"); 
    document.getElementById("container").style.display = "block"; 
} else { 
    var login = "login.php"; 
    window.location.href = login; 
    console.log("I'm not authenticated;") 
} 

,这是在登录页面上的脚本:

$('#signIn').on("click", function(){ 
var username = $("#username").val(); 
var password = $("#password").val(); 

    ref.authWithPassword({ 
    email : username, 
    password : password 
    }, 

    function(error, authData) { 
    if (error) { 
    switch (error.code) { 
     case "INVALID_EMAIL": 
     errorMessage.innerHTML = "The specified user account email is invalid." 
     console.log("The specified user account email is invalid."); 
     break; 
     case "INVALID_PASSWORD": 
     errorMessage.innerHTML = "The specified user account password is incorrect." 
     console.log("The specified user account password is incorrect."); 
     break; 
     case "INVALID_USER": 
     errorMessage.innerHTML = "The specified user account does not exist." 
     console.log("The specified user account does not exist."); 
     break; 
     default: 
     errorMessage.innerHTML = "Error logging user in" 
     console.log("Error logging user in:", error); 
    } 
    } else { 
    console.log("Authenticated successfully with payload:", authData); 
    window.location.href = "index.php"; 
    remember: "sessionOnly" 
    } 
    }); 
}); 

这一切适用于Chrome罚款,火狐,微软优势,但对于在Internet Explorer 11上的一些原因,它不会保持身份验证。我输入我的详细信息,firebase接受它,但随后它跳回到登录页面,并显示一个控制台日志:我没有通过身份验证。

这就像Internet Explorer将不记得页面刷新后,或重定向后的身份验证状态。

我错过了什么?

+0

互联网探险家是老...我只是说。从来没有见过任何人使用这些天, – amanuel2

+0

我不会用棒触摸,但你知道... –

回答

0

那么...我已经在运行IE 11的不同计算机上测试过相同的应用程序,并且运行正常。我猜测我自己的电脑对它有什么不好的咒语。 :(

0

我在IE11中发现了完全相同的问题,出于某种原因,它似乎是浏览器和Firebase服务器之间的防火墙和代理服务器的问题。登录失败,出现A network error (such as timeout, interrupted connection or unreachable host) has occurred.错误。可以在没有任何问题的情况下连接到firebase的数据库端当追踪问题时,IE甚至不尝试与Google身份验证服务器通信

尝试了很多不同的选项后, )将一个<meta http-equiv="X-UA-Compatible" content="IE=10" />标记放置在HTML页面上的HEAD标记后面,当登录并获取错误时,将页面重定向到其模式设置为IE9的页面,并使用查询参数登录,如下所示:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta http-equiv="X-UA-Compatible" content="IE=9" /> 
    <meta charset="UTF-8"> 
    <title>Login</title> 
</head> 
<body> 
    <script src="/js/shims.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.6.2/firebase.js"></script> 
    <script> 
    (function() { 
    var config = { 
     apiKey: '<your keys>', 
     authDomain: '<your keys>', 
     databaseURL: '<your keys>', 
     storageBucket: '<your keys>', 
     messagingSenderId: '<your keys>' 
    }; 
    firebase.initializeApp(config); 

    function getParameterByName(name, url) { 
     if (!url) 
     url = window.location.href; 
     name = name.replace(/[\[\]]/g, "\\$&"); 
     var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"); 
     var results = regex.exec(url); 
     if (!results) return null; 
     if (!results[2]) return ''; 
     return decodeURIComponent(results[2].replace(/\+/g, " ")); 
    } 

    firebase.auth().onAuthStateChanged(function(user) { 
     if (user) 
     window.location.replace('/'); 
     else { 
     firebase.auth() 
     .signInWithEmailAndPassword(
      getParameterByName('user'), 
      getParameterByName('pass') 
     ) 
     .then(function() { 
      window.location.replace('/'); 
     }) 
     .catch(function(error) { 
      console.log(error); 
     }); 
     } 
    }); 

    }()); 
    </script> 
</body> 
</html> 

您会注意到,这将重定向页面,当用户已登录,你也将需要相当该网页,并将处理不正确的密码等

的代码来调用这个页面应该看起来类似于:

if (err.code === 'auth/network-request-failed') { 
    var uri = '/login.html?user=' 
    + encodeURI(email).replace('@', '%40') + '&pass=' + encodeURI(password); 

    window.location.replace(uri); 
} 
相关问题