I am having a problem with the following function:
function observer() {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
// https://firebase.google.com/docs/reference/js/firebase.User
var uid = user.uid;
console.log("Logged");
// ...
} else {
// User is signed out
// ...
}
});
}
The problem in question is the following:
I read several posts where what they did was put firebase links or change some parameters in the firebase console, but it is not my solution, that's why I open another post,
These are my firebase links:
<script src="https://www.gstatic.com/firebasejs/ui/8.2.1/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/4.6.1/firebase-ui-auth.css" />
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>
<script>
var firebaseConfig = {
apiKey: "-",
authDomain: "-",
projectId: "-",
storageBucket: "-",
messagingSenderId: "-",
appId: "-",
measurementId: "-"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-auth.js"></script>
[1]: https://isstatic.aoverflow.com/k0g9F.png
I censor the configuration parameters
I don't know if someone knows how to solve it, it would help me a lot.
Thank you very much in advance, Regards
The difference with your code is the order. Now firebase-auth.js is before your script.
Note that the scripts are imported based on the order you put them in, eg; if you import a library after importing the script that uses that library, it is logical that it will report an error.
The solution in your case is simple, just put the script that depends on firebase after all the other scripts:
In addition to this, I highly recommend that you put all your scripts at the end of the body tag, so that javascript can fully read the DOM.