I'm writing a basic website wherein I'd like users to be able to sign in to the site using google sign-in. I've attempted to do this through firebase and have had successful results thus far. In their documentation it is stated that users will be stored in the variable "auth" in the firebase real-time databse and their email and user-id will be accessible from said variable. I have followed all of the steps in the documentation as well as using their example file as a guideline. On my account control panel, all users that login to my site are noted along with their user-id and email address. This, however is not the case under the real-time database tab as the database remains blank no matter how many times a user logs in. This poses a major issue as I need to be able to access the user's email address in order to do things such as display it on the web page.
The code I have written is as follows:
<html>
<head>
<title>SEatAMRS auth test</title>
<script src="https://www.gstatic.com/firebasejs/3.2.0/firebase.js"></script>
<script type="text/javascript">
// Initialize Firebase
var config = {
apiKey: "****************2XqEQSO9Z8vhPF5w",
authDomain: "*********-build.firebaseapp.com",
databaseURL: "https://***********-build.firebaseio.com",
storageBucket: "***********-build.appspot.com",
};
firebase.initializeApp(config);
//Creatse a provider object
var provider = new firebase.auth.GoogleAuthProvider();
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;
// ...
});
//Sign out function
firebase.auth().signOut().then(function() {
// Sign-out successful.
}, function(error) {
// An error happened.
});
</script>
</head>
<body>
<h1>Welcome to the Google Sign in Fucntionality Test!</h1>
</html>