Skip to content

[bug]: User type has a different datatype than API.DocumentResponseCollection #102

@Steven24K

Description

@Steven24K

Bug Description

I was trying to fetch all users from the Strapi CMS using the StrapiClient. The user collection type is allready in the CMS when you create a fresh install. I needed to show a list of users of a specific role on the frontend of my website. The return type of the find() method is of type DocumentResponseCollection or DocumentResponse if I'm trying to fetch a single type.

Steps to Reproduce

  1. When you have a blanco Strapi project.
  2. And try to fetch all the users with the following code:
let client = strapi({
            baseURL: process.env.STRAPI_URL + '/api',
            auth: process.env.STRAPI_TOKEN,
        });
const response = await this.client.collection('users').find()
  1. When I try to access properties on response.data, I got an exception that data is not defined. For instance when trying to get the username.

When I log the users to the console I can see that the JSON data is as follows:

Image

Expected Behavior

For now fixed the error by casting the type to any, I would expect that the users collection type has a separate data container. A possible way to fix this would to create a sepperate method on the Strapi Client that is only responsible for fetching the users. The main thing that I noticed is that the users are directly on the response as an array and not wrapped in an object under the data property.

Version

1.4.0

Operating System

Windows

Runtime Environment

Node.js

Logs

Media

No response

Confirmation Checklist

  • I have checked the existing issues
  • I agree to follow this project's Code of Conduct
  • I would like to work on this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugsource: clientSource is the main client objectstatus: to be confirmedThe issue needs to be reproduced or confirmed by a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions