Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- // Initialize Firebase
- const config = {
- apiKey: "AIzaSyBohS0b1b9oMqnXjcPbScGUQuVuPSTrFRg",
- authDomain: "graffite-c9805.firebaseapp.com",
- databaseURL: "https://graffite-c9805.firebaseio.com",
- projectId: "graffite-c9805",
- storageBucket: "graffite-c9805.appspot.com",
- messagingSenderId: "66234725427"
- };
- firebase.initializeApp(config);
- // Get elements
- const txtEmail = document.getElementById('txtEmail');
- const txtPassword = document.getElementById('txtPassword');
- const btnLogin = document.getElementById('btnLogin');
- const btnSignUp = document.getElementById('btnSignUp');
- const btnLogOut = document.getElementById('btnLogout');
- // Add login event
- btnLogin.addEventListener('click', e => {
- // Get email and pass
- const email = txtEmail.value;
- const pass = txtPassword.value;
- const auth = firebase.auth();
- // Sign in
- const promise = auth.signInWithEmailAndPassword(email, pass);
- promise.catch(e => console.log(e.message));
- });
- btnSignUp.addEventListener('click', e => {
- // Get email and pass
- // TODO: CHECK IF E-MAIL EXISTS
- const email = txtEmail.value;
- const pass = txtPassword.value;
- const auth = firebase.auth();
- // Sign in
- const promise = auth.createUserWithEmailAndPassword(email, pass);
- promise
- .catch(e => console.log(e.message));
- window.location.replace("app.html");
- });
- btnLogout.addEventListener('click', e => {
- firebase.auth().signOut();
- // Add a realtime Listener
- firebase.auth().onAuthStateChanged(firebaseUser => { if(firebaseUser) {
- console.log(firebaseUser);
- btnLogout.classList.remove('hide');
- } else {
- console.log('not logged in');
- btnLogout.classList.add('hide');
- }
- });
- });
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement