Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body>
- <h1>Sign-In</h1>
- <div class="container">
- <input id="txt_email" type="email" placeholder="Email">
- <input id="txt_password" type="password" placeholder="Password">
- <button id="btnLogin">Log In</button>
- </div>
- <script src="app.js"></script>
- </body>
- <body>
- <h1>Dashboard</h1>
- <script src="app.js"></script>
- </body>
- (function() {
- // Initialize Firebase
- var config = {
- //config info here
- };
- firebase.initializeApp(config);
- // Get elements
- var txt_email = document.getElementById("txt_email");
- var txt_password = document.getElementById("txt_password");
- var btnLogin = document.getElementById("btnLogin");
- // Add click listener to Log in button
- btnLogin.addEventListener("click", e => {
- //Get username and password
- var email = txt_email.value;
- var password = txt_password.value;
- const auth = firebase.auth();
- //Sign in
- const promise = auth.signInWithEmailAndPassword(email, password);
- promise.catch(e => console.log(e.message));
- });
- //Add a realtime authentication listener
- //fires every time an authentication state changes
- firebase.auth().onAuthStateChanged(firebaseUser => {
- if(firebaseUser)
- {
- console.log(firebaseUser);
- window.location = "dashboard.html";
- }
- else
- {
- console.log("not logged in");
- }
- });
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement