Firebase getIdToken not working

firebase.auth().user doesn't have the user in that moment yet. You have to use the user from firebase.auth().onAuthStateChanged directly like this:

firebase.auth().onAuthStateChanged(function(user) {
    if (user) {
        console.log(user); // It shows the Firebase user
        console.log(firebase.auth().user); // It is still undefined
        user.getIdToken().then(function(idToken) {  // <------ Check this line
           console.log(idToken); // It shows the Firebase token now
        });
    }
});

You can only use firebase.auth().user after firebase.auth().onAuthStateChanged is completed and outside of its scope, otherwise it will be undefined.