Custom role

how to extract the code that subverts the register function so as to allow the user during registration to be assigned a custom role created by the admin (what are the steps to do)

This topic has been created from a Discord post (1247543944368099328) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

Have you considered using a middleware?
I have a middleware that elevates the role for the user once they pass a specific condition:

const res = await next(parent, args, context, info);

if (res && res.value) {
  const adminRole = await strapi
    .query("plugin::users-permissions.role")
    .findOne({ where: { name: "Admin" } })

  if (!adminRole) {
    throw new PolicyError("Admin role not found",
      { errCode: "USER_INFO_REQUEST", })
  }

  if (user.role.id !== adminRole.id) {
    await strapi
      .query("plugin::users-permissions.user")
      .update({ where: { id: user.id }, data: { role: adminRole } })
  }
}

return res;

This is a GraphQL middleware so the next signature is slightly different.

actually, I just had a case for doing this myself and it was not easy to add a middleware to the register function.
There is still a way to do this using a lyfecycle hook.
Take a look at this post:

<@789522672098607115> thanks a lot, can I ask you another info? I would like to implement a chat-bot that is connected via ChatGpt API (OpenAI) but I am seeing that it is not free, could you recommend me some free solution? thank you.

<@789522672098607115> Help me, please :frowning_with_open_mouth:

I don’t have any experience with such a use case.
Maybe others in the community may be able to help