简体   繁体   English

如何使用 firebase 身份验证获取 stream onAuthStateChanged?

[英]How to get stream onAuthStateChanged with firebase auth?

I use flutter plugin firebase_auth: ^0.18.4+1我使用 flutter 插件 firebase_auth: ^0.18.4+1

I get this warning in editor:我在编辑器中收到此警告:

The function expression type 'String Function(FirebaseUser)' isn't of type 'String Function(User)'. function 表达式类型“字符串函数(FirebaseUser)”不是“字符串函数(用户)”类型。 This means its parameter or return type doesn't match what is expected.这意味着它的参数或返回类型与预期不匹配。 Consider changing parameter type(s) or the returned type(s).考虑更改参数类型或返回的类型。

FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Stream<String> get onAuthStateChanged =>
      _firebaseAuth.onAuthStateChanged.map((FirebaseUser user) => user?.uid);

Also the 'onAuthStateChanged' is deprecated. 'onAuthStateChanged' 也被弃用了。 How to change it to get stream on onAuthStateChanged?如何更改它以在 onAuthStateChanged 上获取 stream?

Change this:改变这个:

FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Stream<String> get onAuthStateChanged =>
      _firebaseAuth.onAuthStateChanged.map((FirebaseUser user) => user?.uid);

into this:进入这个:

FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Stream<String> get onAuthStateChanged =>
      _firebaseAuth.authStateChanges().map((User user) => user?.uid);

You need to use User class instead of FirebaseUser .您需要使用User class 而不是FirebaseUser

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

相关问题 Firebase 身份验证().onAuthStateChanged() - Firebase auth().onAuthStateChanged() 在Firebase Auth#onAuthStateChanged上获取Facebook / Google访问令牌? - Get Facebook/Google access token on Firebase Auth#onAuthStateChanged? "firebase.auth().onAuthStateChanged 不工作" - firebase.auth().onAuthStateChanged Not Working Firebase auth onAuthStateChanged 解析为 null - Firebase auth onAuthStateChanged resolving to null firebase auth()。onAuthStateChanged执行提取吗? - Is firebase auth().onAuthStateChanged performing a fetch? 如何在Flutter中将onAuthStateChanged用于Firebase Auth? - How do I use onAuthStateChanged for Firebase Auth in Flutter? 如何构建流控制器以监听 onAuthStateChanged 以进行 Firebase 身份验证? - How to build stream controller to listen to onAuthStateChanged for Firebase Authentication? firebase 或 firebase auth 中的 onAuthStateChanged() 不返回值 - onAuthStateChanged() in firebase or firebase auth does not return values FireBase getAuth 和 onAuthStateChanged 不在“firebase/auth”导入中 - FireBase getAuth and onAuthStateChanged is not in "firebase/auth" import 用于电话身份验证的 Firebase OnAuthStateChanged 即使对于 iOS 也会触发 - Firebase OnAuthStateChanged for Phone Auth fires even for iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM