I am getting the error 'Uncaught TypeError: firebase.auth is not a function'.
My code was working perfectly, and then I implemented my clients api, and discovered that their api already uses and has initialized a different firebase app. So, as I couldn't initialise my firebase app in the usual way (ie. firebase.initializeApp(config) ), I followed the documentation on initializing multiple firebase apps as follows. (This results in the error)
var configOther = {
apiKey: "xxxx",
authDomain: "xxxx",
databaseURL: "xxxx",
projectId: "xxxx",
storageBucket: "xxxx",
messagingSenderId: "xxxx"
};
var firebaseOther = firebase.initializeApp(configOther, "firebaseOther");
console.log("auth: ", firebase.auth(firebaseOther)); //"Uncaught TypeError: firebase.auth is not a function"
Any ideas about what I'm doing wrong here? Many thanks.
Note - I have also tried the following shorthand notation:
firebaseOther.auth()
instead of
firebase.auth(firebaseOther)
but this results in the same error.
I am getting the error 'Uncaught TypeError: firebase.auth is not a function'.
My code was working perfectly, and then I implemented my clients api, and discovered that their api already uses and has initialized a different firebase app. So, as I couldn't initialise my firebase app in the usual way (ie. firebase.initializeApp(config) ), I followed the documentation on initializing multiple firebase apps as follows. (This results in the error)
var configOther = {
apiKey: "xxxx",
authDomain: "xxxx",
databaseURL: "xxxx",
projectId: "xxxx",
storageBucket: "xxxx",
messagingSenderId: "xxxx"
};
var firebaseOther = firebase.initializeApp(configOther, "firebaseOther");
console.log("auth: ", firebase.auth(firebaseOther)); //"Uncaught TypeError: firebase.auth is not a function"
Any ideas about what I'm doing wrong here? Many thanks.
Note - I have also tried the following shorthand notation:
firebaseOther.auth()
instead of
firebase.auth(firebaseOther)
but this results in the same error.
Share Improve this question edited Mar 25, 2019 at 15:24 KENdi 7,7512 gold badges17 silver badges31 bronze badges asked Mar 24, 2019 at 23:15 RicRic 651 gold badge1 silver badge8 bronze badges 8 | Show 3 more comments3 Answers
Reset to default 11You likely skipped the step for including the firebase-auth script in your page, as described by the documentation:
<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.9.1/firebase-app.js"></script>
<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.9.1/firebase-auth.js"></script>
The only explanation is that somewhere in the page, there is another <script>
tag referencing the firebase-app.js
file, eg
<script src="https://www.gstatic.com/firebasejs/5.9.1/firebase-app.js"></script>
This tag will be appearing after your inclusion of firebase.js
or firebase-app.js
and firebase-auth.js
.
What happens is the inclusion of firebase-app.js
sets the value of the global firebase
variable, overriding anything that was previously set.
The solution is to either remove the duplicate Firebase script inclusions or at the very least, make sure the ones you want active are included last.
I had a similar problem which was solved by removing defer
in the HTML that was given by the documentation:
<script src="https://www.gstatic.com/firebasejs/7.17.2/firebase-app.js"></script>
<script defer src="https://www.gstatic.com/firebasejs/7.17.2/firebase-auth.js"></script>
<script defer src="https://www.gstatic.com/firebasejs/7.17.2/firebase-firestore.js"></script>
<script>
tags using the cut-downfirebase-app.js
file as that will overwrite thefirebase
variable. Also check for any use offirebase = ...
– Phil Commented Mar 24, 2019 at 23:56