I am using Firebase for a web application. The goal is to allow a familiar login / registration when a user subscribes or registers on one page and after successful authentication is displayed on the home page.
The stream will look something like this: Login / Register → (allows access) → [Home, Profile, Search, Friends, etc.]
I use Javascript (no AngularJs since I am not completely familiar with it). The problem I am facing is that as soon as the user logs in successfully or logs in, their "user object" becomes invalid when using window.location = 'home.html'
Here is the complete code. I use the sample found by Firebase for the authentication process, but home.html is mine:
<!DOCTYPE html> <html> <head> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script type="text/javascript"> function toggleSignIn() { if (firebase.auth().currentUser) { </script> </head> <body> <div class="jumbotron text-center"> </div> <div class="container"> <div class="jumbotron"> <div class="row"> <div class="col-md-6"> </div> <div class="col-md-6"> <div class="mdl-card mdl-shadow--2dp mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--12-col-desktop"> <div class="mdl-card__title mdl-color--light-blue-600 mdl-color-text--white"> <h2 class="mdl-card__title-text">Sign Up</h2> </div> <div class="mdl-card__supporting-text mdl-color-text--grey-600"> <p>Enter an email and password below and either sign in to an existing account or sign up</p> <input class="mdl-textfield__input" style="display:inline;width:auto;" type="text" id="email" name="email" placeholder="Email"/> <br /><br /> <input class="mdl-textfield__input" style="display:inline;width:auto;" type="password" id="password" name="password" placeholder="Password"/> <br/><br/> <button disabled class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-sign-in" name="signin">Sign In</button> <button class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-sign-up" name="signup">Sign Up</button> <button class="mdl-button mdl-js-button mdl-button--raised" disabled id="quickstart-verify-email" name="verify-email">Send Email Verification</button> <button class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-password-reset" name="verify-email">Send Password Reset Email</button> <div class="quickstart-user-details-container"> sign-in status: <span id="quickstart-sign-in-status">Unknown</span> <div> auth <code>currentUser</code> object value:</div> <pre><code id="quickstart-account-details">null</code></pre> </div> </div> </div> </div> </div> </div> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script src="https://www.gstatic.com/firebasejs/3.2.1/firebase.js"></script> <script> </script> </body> </html>
In addition, the page redirected to the auth screen monitors the state of auth using onAuthStateChanged . In this case, use console.log(user); returns null, although console.log("Attempted sign in); . I copied the initApp function from the Firebase Auth sample. Maybe I'm using it in the wrong place?
<!DOCTYPE html> <html> <head> <meta name ="viewport" content ="width=device-width, initial-scale=1.0"> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <link rel="stylesheet" href="styles.css"> <link rel="stylesheet" href="animations.css"> <script type="text/javascript"> function initApp() { </script>
So, for iterating over the problem and purpose again: I want to be able to authenticate the user on this page (the code above is the login / registration screen), and then send them a set of pages that download content based on their Firebase ID.
source share