# How to find Firebase users not in 'Username-Password-Authentication' with 'Database Action Scripts'?

**URL:** <https://community.auth0.com/t/how-to-find-firebase-users-not-in-username-password-authentication-with-database-action-scripts/101232>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [February 24, 2023, 3:20pm UTC](https://community.auth0.com/t/how-to-find-firebase-users-not-in-username-password-authentication-with-database-action-scripts/101232 "2023-02-24T15:20:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roukmoute](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roukmoute/32/44911_2.png) [@roukmoute](https://community.auth0.com/u/roukmoute)\
**Post date:** [February 24, 2023, 3:20pm UTC](https://community.auth0.com/t/how-to-find-firebase-users-not-in-username-password-authentication-with-database-action-scripts/101232/1 "2023-02-24T15:20:22Z")

</div>

Hello,

I would like to ask you for simple examples to understand the use of “Database Action Scripts” in order to find an existing user in Firebase, in case this person is not already listed in the “Username-Password-Authentication” database.

If it is possible, could you help me to clarify this technical point? I know my request is specific, but I hope you can help me with this. Your input would be greatly appreciated and I thank you in advance for your time and attention.

---

<div class="post-metadata">

**Author:** ![roukmoute](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roukmoute/32/44911_2.png) [@roukmoute](https://community.auth0.com/u/roukmoute)\
**Post date:** [April 17, 2023, 8:03am UTC](https://community.auth0.com/t/how-to-find-firebase-users-not-in-username-password-authentication-with-database-action-scripts/101232/2 "2023-04-17T08:03:00Z")

</div>

Create a new Database Connection named like “Firebase”.  
In `Custom Database` section `Database Action Scripts`, click on `Login` tab.  
And use this kind of script:

```js
async function loginAsync(email, password, callback) {
  //should be updated as new versions of axios are made available (https://auth0-extensions.github.io/canirequire/#axios)
  const axios = require("axios@0.22.0");

  let response;

  try {
    response = await axios.post(
      //store API url in connection settings to better support SDLC environments
      "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=XxxxX",
      //user credentials passed as request body
      {
        email: email,
        password: password,
      },
      {
        timeout: 10000, //end call gracefully if request times out so script can do necessary callback
        headers: {
          //securing api call with apiKey stored in connection settings.
          //quick and easy approach however using M2M tokens is more secure as
          // a secret must not be shared between client and API.
          // "x-api-key": configuration.apiKey,
        },
      }
    );
  } catch (e) {
    console.log(e);
    if (e.response.statusCode === 404) {
      //assuming api returns 404 when email/username/password invalid
      return callback(
        new WrongUsernameOrPasswordError(email, "Invalid credentials provided.")
      );
    }
    //callback for any other error type
    return callback(new Error(e.message));
  }

  try {
    let user = response.data;

    //if using multiple custom db connections in your tenant prefix the
    //user_id with a connection specific key ex: "connName|" + user.user_id
    //this ensures unique user ids across all db connections
    return callback(null, {
      user_id: user.localId,
      nickname: user.email,
      email: user.email,
    });
  } catch (e) {
    return callback(new Error(e.message));
  }
}

```

---

<div class="post-metadata">

**Author:** ![jonathan.morales](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jonathan.morales](https://community.auth0.com/u/jonathan.morales)\
**Post date:** [October 10, 2023, 2:16pm UTC](https://community.auth0.com/t/how-to-find-firebase-users-not-in-username-password-authentication-with-database-action-scripts/101232/3 "2023-10-10T14:16:49Z")

</div>

How would you handle if a user also has MFA in firebase configured?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 19, 2024, 2:11pm UTC](https://community.auth0.com/t/how-to-find-firebase-users-not-in-username-password-authentication-with-database-action-scripts/101232/5 "2024-06-19T14:11:02Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
