有没有办法获得Firebase Auth用户UID? [英] Is there any way to get Firebase Auth User UID?

查看:132
本文介绍了有没有办法获得Firebase Auth用户UID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过NodeJS或Javascript API从Firebase获取Auth User(s)UID。
我附上了截图,以便您知道我在寻找什么。

I am looking to fetch Auth User(s) UID from Firebase via NodeJS or Javascript API. I have attached screenshot for it so that you will have idea what I am looking for.

希望,你们帮我解决这个问题。

Hope, you guys help me out with this.

推荐答案

Auth数据在Firebase 3中是异步的。因此您需要等待事件,然后您才能访问当前登录用户的UID。你将无法得到其他人。如果您已经登录,它也会在应用程序打开时被调用。

Auth data is asynchronous in Firebase 3. So you need to wait for the event and then you have access to the current logged in user's UID. You won't be able to get the others. It will get called when the app opens too, if you're already logged in.

firebase.auth().onAuthStateChanged((user) => {
  if (user) {
    // User logged in already or has just logged in.
    console.log(user.uid);
  } else {
    // User not logged in or has just logged out.
  }
});

在您的应用程序中,您可以保存此用户对象,也可以随时获取当前用户 firebase.auth()。currentUser

Within your app you can either save this user object, or get the current user at any time with firebase.auth().currentUser.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged

这篇关于有没有办法获得Firebase Auth用户UID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆