Generate Unique Username

I have login/signup using social providers. There are cases when users can have the same usernames. In this scenario, I would like to generate a unique username eg. “myusername” → “myusername1” (later user can update his username). It would prevent failing auth with response 404 because of username duplicate.

Any ideas on how to do it?

I solved this by:

  1. Override username from string to uid in extensions/users-permissions/models/User.settings.json

“attributes”: {
“username”: {
“type”: “uid”,
“targetField”: “username”,

  1. Generating uniq value on every registration by oveeriding extensions/users-permissions/services/Providers.js
        const uidService = strapi.plugins['content-manager'].services['uid'];

        const username = await uidService.generateUIDField({
          contentTypeUID: "plugins::users-permissions.user",
          data: { username: body.username },
          field: "username"

       callback(null, {
1 Like