Billy Bob Joel
Billy Bob Joel

Reputation: 209

Firebase React Native Current User confusion

I am attempting to make a "Welcome, {username}" page after the user logs in to my app. I am getting an undefined error when trying to pull the current user info into my view, and am only able to load user data in a componentWillMount wrapper.

What's the best way to get the user data to display after the component "mounts?" Perhaps I am not fully understanding this concept?

Upvotes: 1

Views: 7979

Answers (1)

Mohamed Khalil
Mohamed Khalil

Reputation: 3126

var user = firebase.auth().currentUser;
var name, email, photoUrl, uid, emailVerified;

if (user != null) {
  name = user.displayName;
  email = user.email;
  photoUrl = user.photoURL;
  emailVerified = user.emailVerified;
 uid = user.uid;  // The user's ID, unique to the Firebase project. Do NOT use
               // this value to authenticate with your backend server, if
               // you have one. Use User.getToken() instead.
}

You can get user after login by this code if You use firebase JavaScript

Upvotes: 2

Related Questions