I'm new to JS and Firebase so my question is probably very easy, but I couldn't find anything on the WEB that would answer my question.
I'm working with the firebase tutorial available on youtube. The code I have to capture username and password and pass it to firebase looks like this:
btnLogin.addEventListener('click', e => {
const email = txtEmail.value;
const pass =txtPassword.value();
const auth = firebase.auth();
const promise = auth.signInWithEmailAndPassword(email,pass);
promise.catch(e => console.log(e.message));
});
I'm using webstorm and it getting errors on "=>" and first.
When I try to run this anyway I'm getting
"app.js:19 Uncaught TypeError: Cannot read property 'addEventListener' of null"
which lead to the same "=>"
can someone please explain what this is and how to use it? or point me in the right direction to where to look for more information. when I try to google it I'm always getting logic related topics (ass comparisons).
I'm a real noob in JS so please take it easy on me...
EDIT:
I managed to get the webstorm to work - thanks!
But I'm still getting the same error when the page loads:
"app.js:19 Uncaught TypeError: Cannot read property 'addEventListener' of null"
CODE: app.js:
(function () {
console.log("start");
//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 => {
const email = txtEmail.value;
const pass =txtPassword.value;
const auth = firebase.auth();
const promise = auth.signInWithEmailAndPassword(email,pass);
promise.catch(e => console.log(e.message));
});
}());
index.html:
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="inputEmail" id="txtEmail" class="form-control" placeholder="Email address" required autofocus>
<input type="inputPassword" id="txtPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button id="btnLogIn" class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
<button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="submit">Sign Up</button>
<button id="btnLogOut" class="btn btn-lg btn-primary btn-block hide" type="submit">Log Out</button>
</form>
</div>
<script src="src/app.js"></script>