Nevin
Nevin

Reputation: 375

Getting Firebase Current User Info

How do I get the current user's information in my application without using a listener like onStateChanged ? Right now I'm using:

auth.createUserWithEmailAndPassword(email,password).then(function(user){ }

to get the user info then assign it to a variable .. but when I refresh the page, the variable loses its assigned value

Upvotes: 5

Views: 11339

Answers (2)

Robin-Hoodie
Robin-Hoodie

Reputation: 4984

According to the docs using currentUser should do the trick:

var user = firebase.auth().currentUser;

if (user) {
  // User is signed in.
} else {
  // No user is signed in.
}

Upvotes: 6

Zaid Mirza
Zaid Mirza

Reputation: 3719

Make a synchronous call by using $firebaseAuth service

$firebaseAuth().$getAuth();

It will return the currently signed-in user or null if no user is signed in.

Upvotes: 2

Related Questions