4

I have created a web app project in Firebase. And added all the the Firebase configuration scripts including api keys provided for project. I want to integrate Google Sign-in in web app using firebase and I've followed the documentation provided by Firebase Docs. But the Google sign in button is not working and as soon as I load index.html it is throwing these errors on console. I've tried all the ways to remove these errors but I could not find any solution for this. Please help!

Firebase Web App Error

Errors:

Cannot instantiate firebase-auth - be sure to load firebase-app.js first. 
Cannot instantiate firebase-database - be sure to load firebase-app.js first.
Cannot instantiate firebase-messaging- be sure to load firebase-app.js first. 
Cannot instantiate firebase-functions - be sure to load firebase-app.js first. 

Edit1:

Code:

<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-app.js"></script>

<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script>

<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-functions.js"></script>


<script>
  // Initialize Firebase
  var config = {
  apiKey: "************",
  authDomain: "*******.firebaseapp.com",
  databaseURL: "https://******.firebaseio.com",
  projectId: "**********",
  storageBucket: "****.appspot.com",
  messagingSenderId: "*************"
  };
  firebase.initializeApp(config);
</script>


<!-- Gmail Login Code START -->


<div style="text-align:center;">
  <button onclick = "googleSignin()">Google Signin</button>
  <button onclick = "googleSignout()">Google Signout</button>
</div>

<script>
var provider = new firebase.auth.GoogleAuthProvider();

function googleSignin() {
  firebase.auth().signInWithPopup(provider).then(function(result) {
    // This gives you a Google Access Token. You can use it to access the Google API.
    var token = result.credential.accessToken;
    // The signed-in user info.
    var user = result.user;
    // ...
  }).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;
    // ...
  });
}

function googleSignout() {
  firebase.auth().signOut().then(function() {
    // Sign-out successful.
  }).catch(function(error) {
    // An error happened.
  });
}

</script>

<!-- Gmail Login Code END -->
Dipti
  • 41
  • 1
  • 5
  • Please edit the question to show the relevant code that's not working the way you expect. – Doug Stevenson Aug 04 '18 at 16:57
  • Could you share your code? At first sight it seems to be some firebase configuration problem. – vitomadio Aug 04 '18 at 16:58
  • @Doug Stevenson Okay. Thank you for suggestion. – Dipti Aug 05 '18 at 17:37
  • @Vito Madio Yes sure! – Dipti Aug 05 '18 at 17:38
  • 1
    I shifted the firebas-app.js to next line after firebase.js and cleared the cache. It solved the problem partially and my console is error free now. But still the Google Sign in is not working. The Google Sign in window just pops up and disappears. How should I solve this problem :/ Can anyone help? please – Dipti Aug 06 '18 at 13:28
  • +1 to @Dipti . The firebase-app.js should be after firebase.js. This will solve the problem which is occurring. Firebase docs do not say this. – Adi Dec 30 '18 at 09:58

2 Answers2

7

It is not really an answer but one point that helped me solve this issue is to have the same version number for firebase-app, firebase-messaging etc.

Omar Tariq
  • 7,536
  • 10
  • 38
  • 57
-1

In my experience, for Firebase Authentication, you need these 3 scripts:

<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase-auth.js"></script>
<script src="https://cdn.firebase.com/libs/firebaseui/3.0.0/firebaseui.js"></script>

Firebase UI Reference

double-beep
  • 5,031
  • 17
  • 33
  • 41