I am kind of stuck. In my code, I let a user register/log in through facebook. I use an Oauth token thanks to the cordova facebook plugin which I use to log the user in.
If the user does not exist, I add some facebook info(name, email, profile pic) to my firebase database under users.
My question is how do I retrieve this user (not knowing the auto-generated key). Let's say the user modified his profile pic in facebook, since I stored the data only at the first connexion, it is not reflected in my app.
My database looks like this:
users: {
-JtGR-24WUU2HVX3x5c3d: {
image: http//
name: joe
email: cezd
},
-JtGR-24WUU2HVX3x5c43r: {
image: http//
name: john
email:cezs
}
}
Thank you for your help.
Arnaud
Here is how you should do it:
After an account has been created (and the user is logged in), you will have access to its user id via the $firebaseAuth
service. Here's how you get to it:
// Get the unique id for the user
var uid = $firebaseAuth(<your-firebase-ref>).$getAuth().uid;
Then we can store things under this uid
variable, allowing us to easily do CRUD operations for our account. Here we have an array called programs
under the uid
which contains some programs:
// Specify the path we will be working with
var path = uid + '/programs';
Next we can fetch the programs
array using the path we just defined:
// Get all programs, make sure to include a / after your reference
var programs = $firebaseArray(<your-firebase-ref> + path);
And when it's done loaded, assign the programs to the $scope
so we can use it in our front end.
programs.$loaded()
.then(function(data) {
$scope.programs = data;
})
.catch(function(err) {
$scope.error = 'There was an error with the request';
});