Custom username and password login using Flutter firebase

2,666

You can set up a authentication to Firebase with the firebase_auth plugin for Flutter https://pub.dev/packages/firebase_auth

After that you can utilize Firestore to save the user to a collection called users for example with new fields (username in this case) which is assigned to the user.

Which means that on login you need to also map the custom fields from Firestore to the user object in Flutter. The process of getting Firestore data at the same time you being logged in would look something like this (user is a Firebase User object).

AuthService() {
user = Observable(_auth.onAuthStateChanged);

profile = user.switchMap((FirebaseUser u) {
  if (u != null) {
    return _db
        .collection('users')
        .document(u.uid)
        .snapshots()
        .map((snap) => snap.data);
  } else {
    return Observable.just({});
  }
});
}
Share:
2,666
Sam
Author by

Sam

Updated on December 21, 2022

Comments

  • Sam
    Sam over 1 year

    Anyone knows how to have a custom username and password login for flutter using firebase or any other service? I am not talking about email verification. The user just have to make a username with a password and login.

    • Satria Suria
      Satria Suria over 2 years
      Hi Sam, have you figured out how to do it? Because I'm trying to find out the same thing too.