Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. (function() ){
  2.  
  3.  
  4. //iniciando o firebase
  5.  
  6. var config = {
  7. apiKey: "AIzaSyBV_rLGV-NGZnwols5jY3M6goHbNAEIdT8",
  8. authDomain: "fabricadesoftware-b0e2e.firebaseapp.com",
  9. databaseURL: "https://fabricadesoftware-b0e2e.firebaseio.com",
  10. projectId: "fabricadesoftware-b0e2e",
  11. storageBucket: "fabricadesoftware-b0e2e.appspot.com",
  12. messagingSenderId: "1092883892712"
  13. };
  14. firebase.initializeApp(config);
  15.  
  16.  
  17. //get elements
  18. const txtEmail = document.getElementById('txtEmail');
  19. const txtPassword = document.getElementById('txtPassword');
  20. const txtLogin = document.getElementById('txtLogin');
  21. const txtSignUp = document.getElementById('txtSignUp');
  22. const txtLogout = document.getElementById('txtLogout');
  23.  
  24.  
  25.  
  26. //add login event
  27. btnLogin.addEventListener('click', e => {
  28. const email = txtEmail.value;
  29. const pass = txtPassword.value;
  30. const auth = firebase.auth();
  31.  
  32. //sing In
  33. const promise = auth.singInWithEmailAndPassword(email, pass);
  34. promise.catch(e => console.log(e.message));
  35. });
  36.  
  37. //singup event
  38. btnSingUp.addEventListener('click', e => {
  39. const email = txtEmail.value;
  40. const pass = txtPassword.value;
  41. const auth = firebase.auth();
  42.  
  43. //sing In
  44. const promise = auth.createUserWithEmailAndPassword(email, pass);
  45. promise.catch(e => console.log(e.message));
  46. });
  47.  
  48. btnLogout.addEventListener('click', e=> {
  49. firebase.auth().singOut();
  50. });
  51.  
  52. firebase.auth().onAuthStateChanged(firebaseUser => {
  53. if(firebaseUser){
  54. console.log(firebaseUser);
  55. btnLogout.classList.remove('hide');
  56. } else {
  57. console.log('not logged in');
  58. }
  59. });
  60.  
  61. });
  62.  
  63.  
  64.  
  65. ------------------------------------------------------------------------HTML--------------------------
  66.  
  67.  
  68. <!DOCTYPE html>
  69. <html>
  70. <head>
  71. <meta charset="utf-8">
  72. <title>Firebase</title>
  73. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,500" rel="stylesheet">
  74. <script src="https://www.gstatic.com/firebasejs/4.3.1/firebase.js"></script>
  75.  
  76. </head>
  77.  
  78. <body>
  79. <div class="cpntainer">
  80.  
  81.  
  82. <input id="txtEmail" type="email" placeholder="Email"></br>
  83.  
  84. <input id="txtPassword" type="password" placeholder="Password"></br>
  85.  
  86. <button id="btnLogin" class="btn btn-action">Login</button>
  87. <button id="btnSingUp" class="btn btn-action">Sing up</button>
  88. <button id="btnLogout" class="btn btn-action hide">Log out</button>
  89. </div>
  90.  
  91. </div>
  92. <script src="app.js"></script>
  93.  
  94. </body>
  95.  
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement