简体   繁体   English

获取Firebase当前用户信息

[英]Getting Firebase Current User Info

How do I get the current user's information in my application without using a listener like onStateChanged ? 如何在不使用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 获取用户信息然后将其分配给变量..但是当我刷新页面时,变量会丢失其指定的值

According to the docs using currentUser should do the trick: 根据使用currentUser文档应该做的诀窍:

var user = firebase.auth().currentUser;

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

Make a synchronous call by using $firebaseAuth service 使用$firebaseAuth服务进行同步调用

$firebaseAuth().$getAuth();

It will return the currently signed-in user or null if no user is signed in. 它将返回当前已登录的用户,如果没有用户登录,则返回null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM