3

I would like to acces my firestore databse, by using the UID of each user, like so:

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;

And for getting the UID:

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

This but I keep getting the error

Undefined name 'auth'.
1
  • 1
    Did you initialize the auth variable? Commented Feb 16, 2019 at 14:21

2 Answers 2

5

To use FirebaseAuth in flutter, you must get a reference to such instance. Add this line at the top of your widget/file whenever you need to use Firebase Authentication:

import 'package:firebase_auth/firebase_auth.dart';

FirebaseAuth auth = FirebaseAuth.instance;

Now you can use stuff like auth.currentUser().then(...) like you are doing correctly.

Sign up to request clarification or add additional context in comments.

Comments

1

Undefined name 'FirebaseAuth', and not importing library firebase_auth

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.