I am trying to retrieve a logged in users ID to retrieve information related to him from the database using firebase....
in my HTML page inside tags I have the following -
    var user
    var uid;
    firebase.auth().onAuthStateChanged(user => {
        if(!user) {
            window.location = 'login.html'; //If User is not logged in, redirect to login page
        } else {
            user = firebase.auth().currentUser;
            uid = user.uid;
        }
    });
    console.log("UID: " + uid);
and , it seems to be working in respect to checking if the user is logged in... because if I log in from main page and go to the page this is on it works and goes to the page, but if i go to the page when I am not logged in, it redirects to the login page...
however when i try to do that log statement it prints out uid as undefined... any idea why this is not working?
 
     
    