'Flutter and Firebase - How to sign in using username and password only

I just recently started working with firebase and I can't seem to figure out how to make a user sign up with an email, a username and a password so that later on that user can sign in only using a username and a password, I can do it with email and password but I couldn't figure out how to sign in with username and password, simple explanations are appreciated as I'm new to this, thank you!



Solution 1:[1]

I don't think there's a simple method for signing in with username/password from looking at the FlutterFire docs.

You could query Firestore or whatever db you're using and fetch the email corresponding to the username. FlutterFire also good examples for Firestore that you could repurpose to get the username, so all you have to do in a login method is get the email address associated with the username and them call FirebaseAuth.instance.signInWithEmailAndPassword()

Solution 2:[2]

Instead of an email, we can use a username for authentication with the inbuilt authentication functions; createUserWithEmailAndPassword and signInWithEmailAndPassword. The trick here is that showing the input given by the user for the username field, as an email to the above two functions. So you can preprocess the input given by the user by appending something like "@abc.com" to the end of the username before calling the above two functions. But then you cannot use this email saved in the database for other prebuilt functions that need the user's email.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Owen
Solution 2 janani