I am working with Firebase and AngularJS. I am using Auth authentication for google login and i completed the process.Now i need to retrieve the user data that is stored in local storage like firebase:authUser:.
Once i login with google account in local storage you have firebase:authUser:.created and i need to fetch these details.
I used the following method to store user data
firebase.database().ref('users/' + user.uid).set
({
name: user.displayName,
email: user.email,
token: token
});
The documentation for the Web SDK does not mention that upon successfully authentication, Firebase sets the User object in localStorage. The API reference does not mention this either. I discovered this the same way you have by examining localStorage while trying to configure my Vue app with Firebase.
To retrieve the user from localStorage, you can do the following:
You could have multiple entries in
localStorage
so that's the reason forfilter()
Edit: See Metallica's answer below.
Update (2018-02-21): It seems there is now a section (Web) Authentication State Persistence . Unsure if this was there when I originally posted my answer, but I'm updating this answer to link it since this questions gets moderate attention.
Update 2 (2018-02-21): As stated under Overview of persistence behavior :
So
localStorage
is the default which confirms my original answer before the Firebase JS SDK was open sourced.Just to augment @Franciso Mateo's answer: the mentioned filtering, just returns the key (string) with which the serialized user object is stored in local storage. To get the actual deserialized user object, we need to read the item with this key from local storage:
To get a user's profile information, use the properties of an instance of User. For example:
If you'd like to learn more about how to manage users in Firebase using Web SDK, visit this documentation.