login() {
this.ref = new Firebase('https://myapp.firebaseio.com/');
this.ref.onAuth(this.authDataCallback.bind(this));
this.ref.authWithOAuthPopup('google', function (error, authData) {
if (error) {
console.log('Login Failed!', error);
} else {
console.log('Authenticated successfully');
}
}, {
scope: "email"
});
}
2. Upon success, an authDataCallback method is called with an authData object. I can use this to fetch the user's google email and log it.
authDataCallback(authData) {
if (authData) {
console.log(authData["google"]["email"]);
}
}
3. I want to also check to see if that user already exists in my Firebase data. I only want to allow the authentication if the user already exists.
authDataCallback(authData) {
if (authData) {
var userEmail = authData["google"]["email"];
// TODO: check to see if this email exists in firebase /users
// Do not authenticate unless it does
}
}
I currenlty have a https://myapp.firebaseio.com/users reference that I can use. Inside of this data setup, keys are email addresses so it looks like:
{
"addr...@email.com" : {
username: "Felix",
points: 20
},
"addr...@email.com" : {
username: "Bob",
points: 10
},
etc.
}
So basically, if a user authenticates with addr...@email.com or addr...@email.com, I want them to be authenticated and for it to succeed. Otherwise, I want the authentication to fail.
Thank you so much! I'll post back if I get any success, I'm still working on it now.