简体   繁体   English

Firebase 如何在 Auth 中定义当前用户?

[英]How Firebase defines current user in Auth?

I'm using Firebase Auth with Google and doing everyrhing through Firebase docs, and in my SigninActivity , I have onStart method, which check is there are current user or no.我正在使用 Firebase Auth 与 Google 并通过 Firebase 文档做所有事情,在我的SigninActivity中,我有onStart方法,它检查是否有当前用户。

@Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart");
        // Check if user is signed in (non-null) and update UI accordingly.
        FirebaseUser currentUser = mAuth.getCurrentUser();
        updateUI(currentUser);
    }

and also have并且还有

FirebaseAuth.getInstance().signOut();

which signs out user.注销用户。

And i cannot understand, how Firebase defines current user, when he not logged in yet.我无法理解,当他尚未登录时,Firebase 如何定义当前用户。 Is there are unique ID for app or how?应用程序是否有唯一 ID 或如何?

According to your comments:根据您的评论:

Yes, And also i dont understand, how Firebase knows current user, when he not signed in yet?是的,我也不明白,Firebase 如何知道当前用户,当他还没有登录时? I mean, which criteria Firebase checks in this method FirebaseUser currentUser = mAuth.getCurrentUser()我的意思是,哪个标准 Firebase 在这个方法中检查 FirebaseUser currentUser = mAuth.getCurrentUser()

Firebase "knows" when the current user is logged in or not by checking the FirebaseUser object for nullity. Firebase 通过检查FirebaseUser object 的无效性来“知道”当前用户何时登录。 If the user is logged in, when using the following line of code:如果用户已登录,则在使用以下代码行时:

FirebaseUser currentUser = mAuth.getCurrentUser();

It returns a non nullable FirebaseUser object.它返回一个不可为空的FirebaseUser object。 This is the reason why we always check it for nullity.这就是为什么我们总是检查它的无效性的原因。 If you are using the following line of code:如果您使用以下代码行:

FirebaseAuth.getInstance().signOut();

It means that the FirebaseUser becomes null , which also means that the user has signed out.这意味着FirebaseUser变为null ,这也意味着用户已经退出。

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

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