Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase retrieve the user data stored in local storage as firebase:authUser:

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
});
like image 623
Abraham Avatar asked Aug 19 '16 09:08

Abraham


People also ask

How do I get data from Firebase storage?

There are two ways to download files with Firebase Storage, using references in the SDK or a download URL. iOS and Android users can download files into memory, disk, or from a download URL. The web SDK can download files just from a download URL. StorageReference storageRef = FirebaseStorage.

Does Firebase use Localstorage?

Firebase Storage - Firebase Storage lets you upload and store user generated content, such as files, and images. Firebase Authentication - Firebase helps you authenticate and manage users who access your application. Create and setup your account - Get started using Firebase for free.

How can I get user details from Firebase?

If the user login with a custom "email/password" you don't know anything else about that user (apart from the unique user id). If a user login with Facebook, or with Google sign in, you can get other information like the profile picture url. It is explained here: firebase.google.com/docs/auth/android/… .

Where is user data stored in Firebase?

User properties Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).


1 Answers

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:

const userKey = Object.keys(window.localStorage)
  .filter(it => it.startsWith('firebase:authUser'))[0];
const user = userKey ? JSON.parse(localStorage.getItem(userKey)) : undefined;
like image 144
Javad Avatar answered Sep 22 '22 16:09

Javad