Is it possible to use a string rather than email address as a username in Firebase?
I tried, but the createUser
method requires it to be an email address. Is there anyway I can get around this restriction?
You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.
You create a new user in your Firebase project by calling the createUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.
Enable anonymous auth: In the Firebase console, open the Auth section. On the Sign-in Methods page, enable the Anonymous sign-in method. Optional: If you've upgraded your project to Firebase Authentication with Identity Platform, you can enable automatic clean-up.
Given that Firebase Email+Password Authentication does not verify that the email address actually exists, you can just stuff any domain at the end of your string. As long as the result is a syntactically valid email address, it will work:
var name = 'puf'; // TODO: read this from the form where the user enters their username
var password = 'geheim';
var email = name + '@whateverdomain.com';
ref.createUser({ email: email, password: password}...
Note that the user won't have a way to receive password recovery emails with this approach.
Update there is an example of how to implement username+password sign-in in the functions-samples
repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With