• Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login
FusionAuth
  • Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login

Unique usernames but not unique emails

Scheduled Pinned Locked Moved
Q&A
username email uniqueness
2
4
2.8k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    dan
    last edited by 19 May 2021, 17:11

    We have a question about user uniqueness.

    We want to have multiple users with unique usernames, but duplicate email addresses.

    When creating some users, we found FusionAuth wants unique usernames and email addresses. Is there a way to have usernames be unique, but not emails?

    --
    FusionAuth - Auth so modern you can download it.
    https://fusionauth.io

    1 Reply Last reply Reply Quote 0
    • D
      dan
      last edited by 19 May 2021, 17:12

      The recommended course of action is to store the email in the user.data.email field, which is not required to be unique but is still used for activities like 'forgot password' emails. Leave the user.email field blank and use user.username.

      That should work. Support for user.data.email was removed in 1.26 and added back in 1.27.2, so avoid version 1.26.* and 1.27.0 and 1.27.1.

      --
      FusionAuth - Auth so modern you can download it.
      https://fusionauth.io

      K 1 Reply Last reply 17 May 2024, 18:21 Reply Quote 0
      • C cedric.baiker referenced this topic on 19 Aug 2022, 19:40
      • K
        kasir-barati @dan
        last edited by 17 May 2024, 18:21

        Hey @dan,

        Would you mind if I ask you to differentiate between uniqueUsername and username both in updateUser and register in FusionAuth Typescript Client?

        await fusionAuthClient.updateUser(id, {
          // ...
          user: {
            uniqueUsername: username,
          },
        });
        await fusionAuthClient.updateUser(id, {
          // ...
          user: {
            username: username,
          },
        });
        await fusionAuthClient.register('', {
          // ...
          user: {
            username,
          },
        });
        await fusionAuthClient.register('', {
          // ...
          user: {
            uniqueUsername,
          },
        });
        

        Questions

        1. If I use username instead of uniqueUsername, then should I enforce uniqueness manually in my NestJS app?
        2. If I use uniqueUsername then will I have access to it as preferred_username returned by FusionAuth?
        K 1 Reply Last reply 18 May 2024, 09:34 Reply Quote 0
        • K
          kasir-barati @kasir-barati
          last edited by kasir-barati 18 May 2024, 09:34

          I tried to specify both username and email and I got this error:

          {
            statusCode: 400,
            exception: {
              fieldErrors: {
                'user.email': [
                  {
                    code: '[blank]user.email',
                    message: 'You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].'
                  }
                ],
                'user.username': [
                  {
                    code: '[blank]user.username',
                    message: 'You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].'
                  }
                ]
              },
              generalErrors: []
            }
          }
          

          So basically I guess my best bet is to manually enforce uniqueness of username in my backend. But it could have been less cumbersome if I could delegate it to FusionAuth.

          I guess what I am trying to emphasis here is the fact that just by saving username in user.data we will be able to have both username and email but applying rules such as uniqueness would require more manual labor. Cannot we just tell FusionAuth to make sure that user.data.username should be unique in that app or tenant?

          Side note: Since my question is deviating from the OP I'll create a new post and reference this one.
          1 Reply Last reply Reply Quote 0
          1 out of 4
          • First post
            1/4
            Last post