How do I create users without email in firebase?

Viewed 2728

I am building a mobile app for a company with a few employees. Each employee has a unique employee ID that can be used as their account identifier. I would like to know how I could create these users in firebase using their employee ID as the username / id as a preset password.

Something like:

[
  {
    "emp_id": 123, //Login username
    "passwordHash": "LKWrHLwsFlbY4AylsPQ", //Password
    "name": "John Doe"
  },
  {
    "emp_id": 456,
    "passwordHash": "ZQXyTXf8EXlAWX1f",
    "name": "Jane Doe"
  }
]

The employees will have an ID to login that will never change and a password that they can change at will. There is no way to sign up / register. Any new employee will be manually added by an admin.

How to I set up this type of authentication method in firebase? They seem to be forcing their own auth systems (which are neat and all, but not what I need)

1 Answers

There is no built-in support in Firebase for signing in with just a username and a password. The closest you can get with the built-in providers is to create accounts with fake email addresses, such as 123@company.com. But it's less then ideal, since it is somewhat assumed that you can send password reset emails for email+password accounts.

Since none of the built-in identify providers do what you need, you need to create a custom authentication provider for this. This requires that you can run code to mint tokens in a trusted environment, which can be for example your development machine, a server you control, or Cloud Functions for Firebase.

For an example of a custom provider implementing username+password authentication on Cloud Functions, have a look at this page in the function-samples repo.

Related