簡體   English   中英

Firebase 身份驗證錯誤:未定義名稱'auth'

[英]Firebase authentication error: Undefined name 'auth'

我想通過使用每個用戶的 UID 來訪問我的 firestore 數據庫,如下所示:

return new StreamBuilder(
    stream: Firestore.instance.collection('users').document(uid).snapshots(),
    builder: (context, snapshot) {
      if (!snapshot.hasData) {
        return new Text("Loading");
      }
      var userDocument = snapshot.data;

並獲取 UID:

final FirebaseUser user = auth.currentUser().then((FirebaseUser user) {
  final userid = user.uid;
});

這但我不斷收到錯誤

Undefined name 'auth'.

要在FirebaseAuth中使用FirebaseAuth ,您必須獲得對此類實例的引用。 每當您需要使用 Firebase 身份驗證時,在您的小部件/文件頂部添加此行:

import 'package:firebase_auth/firebase_auth.dart';

FirebaseAuth auth = FirebaseAuth.instance;

現在你可以使用像auth.currentUser().then(...)這樣的東西,就像你做得對一樣。

未定義名稱“FirebaseAuth”,並且未導入庫 firebase_auth

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM