<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unique username and email at the same time]]></title><description><![CDATA[<h3><code>username</code>, and <code>email</code> uniqueness.</h3>
<p dir="auto">We wanna let users to register with unique usernames, and email addresses. I know that we can store the email/username in the <code>user.data</code> field, which is not required to be unique. And we know that we cannot specify <code>username</code> and <code>email</code> at the same time. Look at this error message you'll get when you try to specify both:</p>
<pre><code class="language-json">{
  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: []
  }
}
</code></pre>
<p dir="auto">I was trying to update a user with following code:</p>
<pre><code class="language-ts">await fusionAuthClient.updateUser(id, {
  user: {
    lastName: updateUserInfoDto.lastName,
    firstName: updateUserInfoDto.firstName,
    uniqueUsername: updateUserInfoDto.username,
  },
});
</code></pre>
<p dir="auto">So here is a similar Q&amp;A: <a href="https://fusionauth.io/community/forum/post/3055">https://fusionauth.io/community/forum/post/3055</a></p>
<h1>Qustion</h1>
<p dir="auto">I am trying to emphasis that just by saving <code>username</code> in <code>user.data</code> we will be able to have both <code>username</code> and <code>email</code> but applying rules such as uniqueness would require more manual work. Cannot we just tell FusionAuth to make sure that <code>user.data.username</code> should be unique in that <em>application</em> or <em>tenant</em>?</p>
<p dir="auto">I really do not like to check it manually in my backend considering how costly and inefficient it would be;</p>
<ol>
<li>Send an HTTP req to FusionAuth API to fetch all the users.</li>
<li>Loop over them to verify <code>user.data.username</code> is not equal to the one that is entered by the user.</li>
<li>Update user.</li>
</ol>
<p dir="auto">Or at least that's how I though about its implementation.</p>
]]></description><link>https://fusionauth.io/community/forum/topic/2684/unique-username-and-email-at-the-same-time</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 16:44:25 GMT</lastBuildDate><atom:link href="https://fusionauth.io/community/forum/topic/2684.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 May 2024 09:47:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unique username and email at the same time on Thu, 23 Jan 2025 15:37:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/2737">@kasir-barati</a> Hiya, welcome to FusionAuth. Sorry, just ran across your forum post today.</p>
<p dir="auto">There is no way to assign constraints to <code>user.data</code> fields within FusionAuth, but there is <a href="https://github.com/FusionAuth/fusionauth-issues/issues/1149" rel="nofollow ugc">an open issue</a> that I encourage you to upvote.</p>
<p dir="auto">You can require usernames to be unique in a tenant, <a href="https://fusionauth.io/docs/get-started/core-concepts/tenants#username-settings" rel="nofollow ugc">using the <code>Unique usernames</code> setting</a>. It is, however a feature which requires a paid plan.</p>
<p dir="auto">Another alternative, rather than</p>
<blockquote>
<p dir="auto">fetching all users and then looping over users<br />
would be to <a href="https://fusionauth.io/docs/lifecycle/manage-users/search/user-search-with-elasticsearch" rel="nofollow ugc">search for the username</a> before creating the user. Using the search functionality that wouldn't require scanning all the users. You can use a <a href="https://fusionauth.io/docs/extend/events-and-webhooks/events/user-create" rel="nofollow ugc">transactional webhook</a> to fail user creation if your uniqueness rules are not met.</p>
</blockquote>
]]></description><link>https://fusionauth.io/community/forum/post/7777</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/7777</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Thu, 23 Jan 2025 15:37:28 GMT</pubDate></item><item><title><![CDATA[Reply to Unique username and email at the same time on Sat, 29 Jun 2024 11:41:25 GMT]]></title><description><![CDATA[<p dir="auto">Ahhhhhh, this error is getting on my nerves: <code>You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email]</code></p>
<p dir="auto">The thing is that I am setting the user's email to enable them login and then inside <code>data</code> object I am setting a <code>username</code> for the future use, but as of now it is kinda random and automatically generated at the registration time.</p>
<p dir="auto">So why the heck is FusionAuth SDK for Typescript returns <strong>a client response</strong> with this error is a mystery for me.</p>
<p dir="auto">It should not do it under normal circumstances, according to my understanding you can only use <code>email</code> or <code>username</code>, and I am setting <code>email</code> as the way to login but <code>username</code> is inside the <code>data</code> and that should not interfere with anything IMO.</p>
<p dir="auto">I am trying to update this user that was created automatically with Terraform:</p>
<pre><code class="language-tf">resource "fusionauth_user" "you-say-temp-user" {
  tenant_id                = fusionauth_tenant.you-say-tenant.id
  email                    = "souma.kazuya@you-say.com"
  first_name               = "Souma"
  last_name                = "Kazuya"
  password                 = "souma.kazuya"
  skip_verification        = true
  password_change_required = false
  data = jsonencode({
    username : "souma_kazuya"
  })
}
</code></pre>
<p dir="auto">And here is the TS code that I am using to update it, as you can see I am not even touching <code>username</code>:</p>
<pre><code class="language-ts">await this.fusionAuthClient.updateUser(id, {
  user: {
    lastName: updateUserInfoDto.lastName,
    firstName: updateUserInfoDto.firstName,
  },
});
</code></pre>
<p dir="auto">It would be really great if someone could leave a comment setting myself aside ありがとう.</p>
]]></description><link>https://fusionauth.io/community/forum/post/7356</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/7356</guid><dc:creator><![CDATA[kasir-barati]]></dc:creator><pubDate>Sat, 29 Jun 2024 11:41:25 GMT</pubDate></item><item><title><![CDATA[Reply to Unique username and email at the same time on Sat, 29 Jun 2024 10:16:55 GMT]]></title><description><![CDATA[<p dir="auto">Coming back to this thread to update you on something really weird, FusionAuth is throwing an error when I try to have <code>email</code> and <code>user.data.username</code>. I thought FusionAuth really do not care about what is inside the <code>data</code>. Or maybe I am misconfiguring somethings <img src="https://fusionauth.io/community/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f615.png?v=rcgg4tg866g" class="not-responsive emoji emoji-android emoji--confused" style="height:23px;width:auto;vertical-align:middle" title=":confused:" alt="😕" />.</p>
<p dir="auto">It's error message: <code>You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].</code></p>
]]></description><link>https://fusionauth.io/community/forum/post/7355</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/7355</guid><dc:creator><![CDATA[kasir-barati]]></dc:creator><pubDate>Sat, 29 Jun 2024 10:16:55 GMT</pubDate></item><item><title><![CDATA[Reply to Unique username and email at the same time on Thu, 23 May 2024 11:11:27 GMT]]></title><description><![CDATA[<p dir="auto">I can also think of one <strong>ugly</strong> solution which is not very pleasant for the users and that would be generating usernames by concatenating <code>firstName</code>, <code>lastName</code> and a random hexadecimal string.</p>
]]></description><link>https://fusionauth.io/community/forum/post/7293</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/7293</guid><dc:creator><![CDATA[kasir-barati]]></dc:creator><pubDate>Thu, 23 May 2024 11:11:27 GMT</pubDate></item><item><title><![CDATA[Reply to Unique username and email at the same time on Thu, 23 May 2024 11:07:19 GMT]]></title><description><![CDATA[<p dir="auto">It seems like I do not have any mean to implement this in FusionAuth, I search for a way to define new constraints in DB for <code>user.data</code> field but no luck.</p>
<p dir="auto">Then the other option is a vulgar way of doing it, fetching all users and then looping over users and comparing the <code>user.data.username</code> with the new one. It is not gonna work in a medium-size or large user base app.</p>
<p dir="auto">I can think of one more option which is saving all usernames in my MongoDB database which can work but is not what I would volunteer for it.</p>
<p dir="auto">Any suggestion?</p>
]]></description><link>https://fusionauth.io/community/forum/post/7292</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/7292</guid><dc:creator><![CDATA[kasir-barati]]></dc:creator><pubDate>Thu, 23 May 2024 11:07:19 GMT</pubDate></item><item><title><![CDATA[Reply to Unique username and email at the same time on Sat, 18 May 2024 09:58:10 GMT]]></title><description><![CDATA[<p dir="auto">GH issue: <a href="https://github.com/FusionAuth/fusionauth-issues/issues/185" rel="nofollow ugc">https://github.com/FusionAuth/fusionauth-issues/issues/185</a></p>
]]></description><link>https://fusionauth.io/community/forum/post/7282</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/7282</guid><dc:creator><![CDATA[kasir-barati]]></dc:creator><pubDate>Sat, 18 May 2024 09:58:10 GMT</pubDate></item></channel></rss>