2017-08-11 81 views
0

我遇到問題,無法登錄到我的網站上。我已經使用了Firebase示例代碼,但似乎沒有任何工作。該域名被列入白名單,並且在控制檯上沒有標記問題。該代碼在其他頁面上工作,以登錄用戶,所以我不明白爲什麼它不在這裏工作。Firebase網絡登錄無法正常工作

下面是代碼:

<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"> 
    </script> 

    <script> 
     // Initialize Firebase 
     var config = { 
     apiKey: "AIzaSyDb7PQjkzYvTZPIFVkBY2NjsjiTTtBMJqM", 
     authDomain: "jaunt-ddc86.firebaseapp.com", 
     databaseURL: "https://jaunt-ddc86.firebaseio.com", 
     projectId: "jaunt-ddc86", 
     storageBucket: "jaunt-ddc86.appspot.com", 
     messagingSenderId: "40972835460" 
     }; 

     firebase.initializeApp(config); 

    function handleSignUp() { 
     var email = document.getElementById('email').value; 
     var password = document.getElementById('password').value; 
     if (email.length < 4) { 
     alert('Please enter an email address.'); 
     return; 
     } 
     if (password.length < 4) { 
     alert('Please enter a password.'); 
     return; 
     } 

     window.location.replace("https://app.jaunt-app.co.uk/home"); 
     // Sign in with email and pass. 
     // [START createwithemail] 
     firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { 
     // Handle Errors here. 
     var errorCode = error.code; 
     var errorMessage = error.message; 
     // [START_EXCLUDE] 
     if (errorCode == 'auth/weak-password') { 
      alert('The password is too weak.'); 
     } else { 
      console.error(error); 
     } 
     // [END_EXCLUDE] 
     }); 
     // [END createwithemail] 
    } 
    function sendPasswordReset() { 
     var email = document.getElementById('email').value; 
     // [START sendpasswordemail] 
     firebase.auth().sendPasswordResetEmail(email).then(function() { 
     // Password Reset Email Sent! 
     // [START_EXCLUDE] 
     alert('Password Reset Email Sent!'); 
     // [END_EXCLUDE] 
     }).catch(function(error) { 
     // Handle Errors here. 
     var errorCode = error.code; 
     var errorMessage = error.message; 
     // [START_EXCLUDE] 
     if (errorCode == 'auth/invalid-email') { 
      alert(errorMessage); 
     } else if (errorCode == 'auth/user-not-found') { 
      alert(errorMessage); 
     } 
     console.log(error); 
     // [END_EXCLUDE] 
     }); 
     // [END sendpasswordemail]; 
    } 
    </script> 

    <body> 
    <div id="main"> 
    <section id="landing"> 
     <div class="layer"> 
      <div class="outer"> 
       <div class="middle"> 
        <div class="inner"> 
         <img src="img/pin.png" alt="Jaunt Map Pin" id="signupMapPin" /> 
         <br /> 
         <div id="welText"> 
          <div class="signup"> 
           <h2 class="signup-title">Sign up for Jaunt now!</h2> 
           <br /> 
           <input class="mdl-textfield__input" type="text" id="name" name="name" placeholder="Name"/> 
           <br /> 
           <input class="mdl-textfield__input" type="text" id="email" name="email" placeholder="Email"/> 
           <br /> 
           <input class="mdl-textfield__input" type="password" id="password" name="password" placeholder="Password"/> 
           <br /> 
           <!--<a href="comingsoon.html">--> 
           <button disabled class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-sign-in" name="signin"> 
            Sign In 
           </button> 
           <button class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-sign-up" name="signup"> 
            Sign Up 
           </button> 
           <!--</a>--> 
           <br /><br /> 
           <button class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-password-reset" name="verify-email">Reset Your Password</button> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
    </section> 

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.min.js"></script> 
    </div> 
    </body> 
</html> 
+0

我很抱歉,如果這是一個愚蠢的問題,但您是否從Firebase控制檯啓用電子郵件/密碼身份驗證?因爲我一直使用Firebase,所以有時候我仍然犯這個錯誤。 –

+0

@JenPerson哈哈多數民衆贊成在我雖然我做錯了,但沒有它與谷歌和Facebook一起啓用 – AngryCubeDev

+0

所以當你說登錄不起作用,一個新的用戶不會創建? –

回答

0

您將會重定向:window.location.replace("https://app.jaunt-app.co.uk/home");成功創建用戶之前。

+0

點擊按鈕時甚至不會重定向! – AngryCubeDev

+0

您是否將點擊處理程序添加到按鈕?我沒有在你的代碼中看到它。 – bojeil