Auth endpoint /auth/local is over-fetching data - how to create custom controller?

Hi Jasonleow,
I recently had the same problem, and I found out that there’s also another method to do it without having to customize the code. If you install the graphql extension, you can send a POST request to the “/graphql” endpoint with a JSON body that looks like this:

{
    query: `
        mutation ($email: String!, $password: String!) {
            login(input: { identifier: $email, password: $password }) {
                jwt,
                user {
                    username,
                    email
                }
            }
        }
    `,
    variables: {
        email,
        password
    }
}

This will only get the token, username and email of the user. Just be aware that both data and errors are sent a little bit differently then the REST APIs, so your application code should be slightly changed accordingly.

Here you can find the Strapi docs about graphql

Of course, you can use graphql only for this request and keep everything else with the REST APIs :slightly_smiling_face: