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

    Is there any way within FusionAuth to enforce the uniqueness of a username within an application?

    Scheduled Pinned Locked Moved
    Q&A
    2
    3
    1.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.
    • joshuaJ
      joshua
      last edited by

      Is there any way within FusionAuth to enforce the uniqueness of a username within an application?

      1 Reply Last reply Reply Quote 0
      • joshuaJ
        joshua
        last edited by

        The username on the user (user.username) is unique and can be used to login. The username on the registration registration.username is not unique and cannot be used to login, it is intended to be used for display in an application.

        K 1 Reply Last reply Reply Quote 0
        • K
          kasir-barati @joshua
          last edited by kasir-barati

          Hey @joshua,

          Thanks for this Q&A, I have a question, what does this uniqueUsername mean and how it differs from username? E.g. code written in TS:

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

          How I register a user:

          await fusionAuthClient.register('', {
            sendSetPasswordEmail: true,
            skipVerification: false,
            registration: {
              applicationId,
            },
            user: {
              email,
              lastName,
              firstName,
              memberships,
              fullName: `${firstName} ${lastName}`,
              username,
            },
          });
          

          Side note

          I need username to be unique and I am utilizing @fusionauth/react-sdk's useFusionAuth hook. So basically IDK whether user.preferred_username is gonna be filled when I use uniqueUsername both in registration and updateUser or not.

          And if the answer is negative* then should I manually write code to enforce uniqueness of username in my NestJS app?

          *meaning if I use uniqueUsername in my frontend app preferred_username would be undefined

          1 Reply Last reply Reply Quote 0
          • First post
            Last post