Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 628
Nevin Avatar asked Nov 22 '16 14:11

Nevin


2 Answers

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.
}
like image 117
Robin-Hoodie Avatar answered Oct 13 '22 05:10

Robin-Hoodie


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.

like image 26
Zaid Mirza Avatar answered Oct 13 '22 05:10

Zaid Mirza