Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <body>
  2. <h1>Sign-In</h1>
  3.  
  4. <div class="container">
  5. <input id="txt_email" type="email" placeholder="Email">
  6. <input id="txt_password" type="password" placeholder="Password">
  7.  
  8. <button id="btnLogin">Log In</button>
  9. </div>
  10.  
  11. <script src="app.js"></script>
  12. </body>
  13.  
  14. <body>
  15. <h1>Dashboard</h1>
  16.  
  17. <script src="app.js"></script>
  18. </body>
  19.  
  20. (function() {
  21.  
  22. // Initialize Firebase
  23. var config = {
  24. //config info here
  25. };
  26. firebase.initializeApp(config);
  27.  
  28. // Get elements
  29. var txt_email = document.getElementById("txt_email");
  30. var txt_password = document.getElementById("txt_password");
  31. var btnLogin = document.getElementById("btnLogin");
  32.  
  33. // Add click listener to Log in button
  34. btnLogin.addEventListener("click", e => {
  35. //Get username and password
  36. var email = txt_email.value;
  37. var password = txt_password.value;
  38. const auth = firebase.auth();
  39.  
  40. //Sign in
  41. const promise = auth.signInWithEmailAndPassword(email, password);
  42. promise.catch(e => console.log(e.message));
  43. });
  44.  
  45.  
  46. //Add a realtime authentication listener
  47. //fires every time an authentication state changes
  48. firebase.auth().onAuthStateChanged(firebaseUser => {
  49. if(firebaseUser)
  50. {
  51. console.log(firebaseUser);
  52. window.location = "dashboard.html";
  53. }
  54. else
  55. {
  56. console.log("not logged in");
  57. }
  58. });
  59.  
  60. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement