Username authentication instead of email

2019-01-04 02:53发布

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条回答
▲ chillily
2楼-- · 2019-01-04 03:34

Simple: you can add any domain behind the username. So once you have determined the user name, register your user with <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.

查看更多
Anthone
3楼-- · 2019-01-04 03:48

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 :

  1. User send username and password to cloud function url via query params (GET) or request body (POST)

  2. Cloud funtion will check whether username and password is valid (ex: from realtime database)

  3. 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

  4. Client then can login using that customToken

查看更多
你好瞎i
4楼-- · 2019-01-04 03:56

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:

  1. Prompt the username to login with username and password
  2. Verify the username exists in your database and retrieve the corresponding email address for that account
  3. Pass this email address to the login process seamlessly
查看更多
登录 后发表回答