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
172 views
in Technique[技术] by (71.8m points)

javascript - 如何在Firebase的authStateObserver中调用.isNewUser()(How to call .isNewUser() in authStateObserver in firebase)

Its not at all clear in the documentation how to check if a freshly logged in user has logged into my web app previously.

(在文档中根本不清楚如何检查新登录的用户之前是否已登录我的Web应用程序。)

There is an isNewUser() call referenced here:

(这里引用了一个isNewUser()调用:)

AdditionalUserInfo

(AdditionalUserInfo)

What is not clear is how to get access to this call when using a firebase auth call and observer.

(尚不清楚的是,在使用Firebase身份验证调用和观察者时,如何访问此调用。)

firebase.auth().onAuthStateChanged(authStateObserver);

The authStateObserver gets a user object after the person logs in using the provider specified.

(人员使用指定的提供程序登录后,authStateObserver将获得一个用户对象。)

This user object cannot be used to call .isNewUser() so how does one get to the additionalUserInfo which has the call to .isNewUser() from inside this authStateObserver?

(无法使用此用户对象来调用.isNewUser(),因此如何从此authStateObserver内部获取到具有.isNewUser()调用的AdditionalUserInfo?)

This is in javascript in a web app.

(这是在网络应用程序中的javascript中。)

  ask by michael powers translate from so

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

1 Answer

0 votes
by (71.8m points)

firebase.auth().onAuthStateChanged only triggers with the FirebaseUser .

(firebase.auth().onAuthStateChanged仅使用FirebaseUser触发。)

You can't get additionalUserInfo or any credential eg.

(您无法获得additionalUserInfo或任何credential例如。)

OAuth tokens associated with the result from that observer.

(与该观察者的结果相关联的OAuth令牌。)

You have to get it from the firebase.auth.UserCredential after the sign-in promise resolves.

(登录承诺解析后,您必须从firebase.auth.UserCredential获取它。)

As these results are only available once on sign-in and Auth does not refresh OAuth credentials or actively update underlying OAuth profiles, Firebase Auth opted not to provide them in onAuthStateChanged listener as it could mislead developers to think that the listener can be used to listen/get new credentials or additional user data when in reality this information is only available once on sign-in.

(由于这些结果仅在登录时可用一次,并且Auth不会刷新OAuth凭据或主动更新基础OAuth配置文件,因此Firebase Auth选择不在onAuthStateChanged侦听器中提供它们,因为这可能会误导开发人员,认为该侦听器可用于侦听/获取新凭据或其他用户数据,而实际上该信息仅在登录时可用。)

The observer will only observe changed to the FirebaseUser, eg.

(观察者只会观察到对FirebaseUser的更改,例如。)

sign-in or sign-out events.

(登录或退出事件。)


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

...