Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Authentication without email as username?

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?

like image 929
Lisa Avatar asked Aug 13 '15 14:08

Lisa


People also ask

Can I use Firebase just for authentication?

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.

How do I change my Firebase authentication username?

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.

How do you create an anonymous account on Firebase?

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.


1 Answers

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.

like image 131
Frank van Puffelen Avatar answered Sep 19 '22 17:09

Frank van Puffelen