gpt4 book ai didi

java - FirebaseAuth.getInstance().getUid() - 它是如何工作的?

转载 作者:行者123 更新时间:2023-12-02 10:18:41 24 4
gpt4 key购买 nike

我对此有 3 个问题:

FirebaseAuth.getInstance().getUid()
  1. 根据规范,getInstance() 返回 FirebaseAuth 的实例类,但 getUid 在该类中不起作用。但它有效。怎么办?

  2. 如果这是一个新用户,getUid 似乎会生成唯一的 ID,但它规范中没有写。这个功能是如何工作的?

  3. 什么时候抛出异常或返回 null ?

谢谢,亚历克斯

最佳答案

来自documentation

公共(public)抽象String getUid()

Returns a user identifier as specified by the authentication provider. For example, if this object corresponds to a Google user, returns a Google user ID. For phone number accounts, the UID will be the normalized phone number in E.164 format.

什么时候抛出异常或者返回null?

这是在单例和方法 getUid() 内部处理的,我找不到任何有关抛出的文档

为了让 getUid() 工作,您需要首先让当前用户登录以获取 ID

FirebaseAuth.getInstance().getCurrentUser().getUid();

您可以通过首先检查当前用户是否为 != null 来防止 null 或仅使用 AuthListener 来检查它

FirebaseAuth currentUser = FirebaseAuth.getInstance().getCurrentUser();

if(currentUser != null)
String uid = currentUser.getUid();

关于java - FirebaseAuth.getInstance().getUid() - 它是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54486856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com