0

I've implemented Firebase Authentication in my app with role-based API using firebase admin. When retrieving a user's data or listing all user's data from firebase, it does not include the user's disabled status.

I'm attempting to create the ability for app administrators to tell if a user account is Active or Disabled, and have the option to "flip the switch" as needed to manage their users.

Here are my controllers for each route in the API:

List all Users

    // list all users route
    app.get('/users', [
      authenticationCheck.isAuthenticated,
      authorizedCheck.isAuthorized({ hasRole: ['admin', 'user'] }),
      indexController.all,
    ])
      
    // list all users controller
    async function all(req, res) {
      try {
        const listUsers = await admin.auth().listUsers(),
          users = listUsers.users.map(mapUser)
        console.log('userList', users)
        return res.status(200).send({ users })
      } catch (err) {
        return handleError(res, err)
      }
    }

Get user by id

    // get user by id route
    app.get('/users/:id', [
      authenticationCheck.isAuthenticated,
      authorizedCheck.isAuthorized(
        { hasRole: ['admin', 'user'], allowSameUser: true },
      ),
      indexController.get,
    ])

    // get user by id controller
    async function get(req, res) {
      try {
        const { id } = req.params,
          user = await admin.auth().getUser(id)
        return res.status(200).send({ user: mapUser(user) })
      } catch (err) {
        return handleError(res, err)
      }
    }

Am I missing something? How do I retrieve a user's disabled status from Firebase using Firebase Admin?

Update

This issue is resolved. I found that the I wasn't mapping "disabled" in the mapUser function that I am using to also map customClaims.

Adam
  • 1
  • 2
  • 1
    `listUsers()` function does return array of UserRecords in user property. What is the output when you log users ? – Dharmaraj Feb 13 '22 at 19:16
  • @Dharmaraj, great question. This is what Firebase returns: { "users": [ { "uid": "user-id", "email": "user's-email", "displayName": "user's display name", "role": "custom role", "lastSignInTime": "Sun, 13 Feb 2022 17:24:22 GMT", "creationTime": "Thu, 13 Jan 2022 14:04:56 GMT" }, { ... repeated for the next user }, ] } – Adam Feb 13 '22 at 22:01
  • I found the issue. "Disabled" wasn't included in my mapUser function, where I was also mapping custom claims. This issue is resolved. – Adam Feb 13 '22 at 22:26

0 Answers0