Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

firebase - FirebaseAuth: What's the difference between the common auth "FirebaseAuth(FirebaseApp var1)" and the .getInstance() version:

When I created a FirebaseAuth with its constructor FirebaseAuth(FirebaseApp var1), I got a question:

What's the difference between the common auth and the .getInstance() version:

The .getInstance() gives you back the auth by which your "getAppInstance()" aka: Firebase App is subscribed.

The "global Auth" of your app if you wish.

So whats the weird thing? If you use the FirebaseAuth(FirebaseApp var1) constructor, it does not uses this "global auth" by default, and yet it still register callbacks when actions are performed directly in it (without getInstance() ofc).

This means that you could have 2 different instanced objects of a FirebaseAuth in 2 different view models, and the listeners of both of them, as long as they are connected via .getInstance().addAuthStateListener(); BOTH will receive the same call back, even if only one of them receives an execution that forces a change in its auth state... this seems obvious,

BUT If you do the aforementioned action without the .getInstance(), only one of the objects will register a callback, as long as they are manually constructed via FirebaseAuth(FirebaseApp var1).

another case:

if you:

.getInstance().addAuthStateListener(); ---> then ---> .signOut() (without getInstance());

// nothing gets registered, not even by the listener of the same auth object on which you are performing the .singOut();

But If:

.addAuthStateListener(); ---> then ---> .signOut() (with FirebaseAuth(FirebaseApp var1) constructor)

//Then all goes as normal, but other instances of a Firebase auth within the same app will not receive any callbacks, just the auth object in which you are performing the executions.

Now this behavior in theory would make it seem that one could sing in multiple auths at the same time, but with a simple scan on SO, it seems that that is not the case.

Why the devs did this? (Maybe I'm the only one that is not sure..) Why not give you the global auth by default? ...but people are still creating phantom FirebaseApps to avoid login in on registration, so this doesn't seem to solve any problem or be of anything useful at all.

OR is that constructor the one to solve all problems?

question from:https://stackoverflow.com/questions/65944993/firebaseauth-whats-the-difference-between-the-common-auth-firebaseauthfireba

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...