Creating a new user through API

System Information
  • Strapi Version:
    4.5.3
  • Operating System:
    Windows - production is Heroku
  • Database:
    MySQL

I am trying to create a new frontend user through an API.
I am able to add a new entry to to the user model with entityService but then I can’t log on with that user.

I have tried about 50 different things and been searching Google for about 20 hours already but I can’t find the answer. I am currently searching through the Github and node_modules.

Here is my code:

      const pw = await auth.hashPassword("testtest");
     
console.log(pw);
      let newUser = await strapi.entityService.create(
        "plugin::users-permissions.user",
        {
          data: {
            username: Email,
            email: Email,
            password: pw,
            provider: 'local',
            confirmed: true,
            OrganizationName: OrganizationName,
            OrganizationId: organizationId,
            TypeOfRegistration: "Admin",
            role: userPerm.id,
            FullName: Name,
            UserId: uuidv4(),
          },
        }
      );
1 Like

I found the solution:

const res = await strapi.entityService.create(
        'plugin::users-permissions.user',
        {
          data: {
            username: 'your-user-name',
            provider: 'local',
            blocked: false,
            password: 'raw-password',
            role: 3,
          },
        }
      );
1 Like