skip to Main Content

I am using firebase and firestore for my app. Once a new user registers their account is made and they are also added to the "users" collection in the firestore. But I can’t access information other than email address (such as firstName, lastName, etc.) from the firebase authentication instance. How and where can I store this information on registration so I can access it from any file or place throughout the app?

User? get currentUser => _firebaseAuth.currentUser;

The instance mentioned above only returns the email and password because the other things (such as firstName, lastName, etc.) are not stored in the firebase authentication database but in the firestore.

I tried using shared_preferences but can’t get that to work. It throws the following error:

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)

2

Answers


  1. The problem is with the logic you are trying to implement. Firebase authentication doesn’t care about first or last name things. It only cares about the email and password used to create the user.

    So usually this is what I’ll do; Store the first and last name directly from the text lfield in your app.

    {
    //after signup is successful and complete
    shared.setString("fname",firstName.text)
    shared.setString("lname",lastName.text)
    }
    
    Login or Signup to reply.
  2. You need to implement Cloud firestore to store user basic bio credentials to use even after they logout

    https://firebase.google.com/docs/firestore/manage-data/add-data

    Use Solutions like SharedPreferences or Hive to persist user details

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search