0

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>
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
WebGavDev
  • 33
  • 7
  • User information is not automatically stored in the database. It is made available to your code and in the security rules for your database. If you want to store the information in the database, you can do so in your own code. See https://stackoverflow.com/questions/14673708/how-do-i-return-a-list-of-users-if-i-use-the-firebase-simple-username-password and this example from our legacy docs: https://www.firebase.com/docs/web/guide/user-auth.html#section-storing – Frank van Puffelen Jul 14 '16 at 14:33

1 Answers1

0

First you get the username and password from the users. Then, validate the credentials in html then, use the signin method in firebase.

GS7
  • 1
  • 7
  • This code provides the user with a pop-up that allows them to then input their google account credentials, thereby authenticating them and allowing them to be signed in to the site from their google account. The functionality that I have added works exactly like it is supposed to, save for the fact that users are not being stored in the database as the firebase documentation states that they should. – WebGavDev Jul 14 '16 at 12:04