Username authentication instead of email
Username authentication instead of email
With Firebase I can sign up and login users using email addresses. However what if I want the app to be username based. For example, you would log in with "Bobzilla" instead of "Bob@mail.com"?
Is this possible with Firebase?
3 Answers
3
Simple: you can add any domain behind the username. So once you have determined the user name, register your user with <username>@vikzillasapp.com
.
<username>@vikzillasapp.com
Note that this will make it impossible to for the user to reset their password if they forget it, since Firebase uses the email address to send the password reset email.
If this doesn't suit your needs, you can roll your own identity provider using the instructions in the Firebase documentation. This requires code that runs in a trusted environment, for which you can use your own server or Cloud Functions for Firebase. There is now even an example of this in the functions-samples repo.
But if you cannot reset passwords in time given the user forget their information, isn't his a flawed approach?
– Sauron
Feb 20 '16 at 15:26
firebase REALLY needs away for you authenticate through user name. Not only email
– Ben Akin
Aug 11 '16 at 18:12
has this been solved?
– Zen
Nov 5 '16 at 15:47
Yes, this is indeed needed.
– MJQZ1347
Jan 3 '17 at 0:18
Instead of using a method where you assign an email address for the user, it might be a better option to lookup an email address in your database.
An example would be:
Interesting idea. I think the problem would be that you would have to have all these emails open on your database.
– StackAttack
Dec 17 '17 at 11:48
It's a interesting idea, but only works if database read permissions don't require signed in user, unless you create a public separated usernames collection.
– Hugo Castelani
May 17 at 20:27
True, however, you would most likely make the database read permissions open because you wouldn't otherwise be able to verify an email exists already when creating an account (to prevent duplicate email addresses)
– Scott D
Jun 15 at 14:08
You can use firebase custom auth. Custom auth is a method which user can login into app using custom token.
But, you need backend code, to create custom token when user send username and password to that backend.
Fortunately, now there is firebase cloud function, with http event, that can solve your problem easily. The step is :
User send username and password to cloud function url via query params (GET) or request body (POST)
Cloud funtion will check whether username and password is valid (ex: from realtime database)
If the username and password valid, cloud function will create custom token using userId (you need to save the userId). And then send it to response body
Client then can login using that customToken
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Ok, so in my code I will tack on a domain to whatever unique username they enter. And so when they sign in I'll just append that domain to their username for authentication. Think I got it then; thanks! It is too bad we can't have control over the password though, as you mentioned if they ever want to change the password I'd have to capture their email as well. Which isn't the case for all apps; a lot of times an email isn't necessary for an app.
– vikzilla
Feb 1 '16 at 3:47