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!
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 -->