Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() ){
- //iniciando o firebase
- var config = {
- apiKey: "AIzaSyBV_rLGV-NGZnwols5jY3M6goHbNAEIdT8",
- authDomain: "fabricadesoftware-b0e2e.firebaseapp.com",
- databaseURL: "https://fabricadesoftware-b0e2e.firebaseio.com",
- projectId: "fabricadesoftware-b0e2e",
- storageBucket: "fabricadesoftware-b0e2e.appspot.com",
- messagingSenderId: "1092883892712"
- };
- firebase.initializeApp(config);
- //get elements
- const txtEmail = document.getElementById('txtEmail');
- const txtPassword = document.getElementById('txtPassword');
- const txtLogin = document.getElementById('txtLogin');
- const txtSignUp = document.getElementById('txtSignUp');
- const txtLogout = document.getElementById('txtLogout');
- //add login event
- btnLogin.addEventListener('click', e => {
- const email = txtEmail.value;
- const pass = txtPassword.value;
- const auth = firebase.auth();
- //sing In
- const promise = auth.singInWithEmailAndPassword(email, pass);
- promise.catch(e => console.log(e.message));
- });
- //singup event
- btnSingUp.addEventListener('click', e => {
- const email = txtEmail.value;
- const pass = txtPassword.value;
- const auth = firebase.auth();
- //sing In
- const promise = auth.createUserWithEmailAndPassword(email, pass);
- promise.catch(e => console.log(e.message));
- });
- btnLogout.addEventListener('click', e=> {
- firebase.auth().singOut();
- });
- firebase.auth().onAuthStateChanged(firebaseUser => {
- if(firebaseUser){
- console.log(firebaseUser);
- btnLogout.classList.remove('hide');
- } else {
- console.log('not logged in');
- }
- });
- });
- ------------------------------------------------------------------------HTML--------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Firebase</title>
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,500" rel="stylesheet">
- <script src="https://www.gstatic.com/firebasejs/4.3.1/firebase.js"></script>
- </head>
- <body>
- <div class="cpntainer">
- <input id="txtEmail" type="email" placeholder="Email"></br>
- <input id="txtPassword" type="password" placeholder="Password"></br>
- <button id="btnLogin" class="btn btn-action">Login</button>
- <button id="btnSingUp" class="btn btn-action">Sing up</button>
- <button id="btnLogout" class="btn btn-action hide">Log out</button>
- </div>
- </div>
- <script src="app.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement