Search code examples
strapi

Version 4.1.9 throws an error: "name": "ApplicationError", "message": "Email already taken" via Postman


My System information

  • Node.js version: v16.13.0
  • NPM version: 8.1.0
  • Strapi version: 4.1.9
  • Database: Postgres
  • Operating system: MacOS

The Issue

I recently setup an instance of Strapi and Postgres via railway (https://railway.app), and tried making a few request to test the api. Upon making POST request to fetch/ update a user that was originally setup through Strapi admin, I am getting an Email already taken 404 error message.

Screenshots

https://freeimage.host/i/HCvcw0P

Steps to reproduce the behavior

  1. Configured user Content-Type by adding a user_role field via Strapi admin (Note that this is not meant to replace the default Strapi user role).
  2. Saved the file, and the entry was successfully saved in the database.
  3. Made a GET Request to https://my-railway-url/api/users to retrieve ALL USERS successfully.
  4. I made a Post request to https://my-railway-url/api/auth/local to get user info along with the JWT token
  5. Received a JWT token along with user information.
  6. Copied the JWT Token and made another POST request - with body set to JSON, entered info to update the existing user
  7. Got an error Email already taken

Expected behavior

User information updated with the new entries.


Solution

  • the strapi user-permissions plugin, has it's own logic of controllers, with would not be the same as standard content-type api's

    to use it you have following routes:

    // LOGIN
    url: `api/auth/local`
    method: POST
    body: {
      identifier: string
      password: string
    }
    
    // ME get current authenticated user
    url: `api/users/me`   // you can add '?populate=*' here
    method: GET
    
    // UPDATE USER
    url: `api/users/:id`  // you can add '?populate=*' here
    method: POST
    body: {
      ...data // < user data
    }
    

    seems ?id=3 is invalid in your query, should be /api/users/3