How to add a constraint to require usernames to be unique?

Hi, I’ve looked long and hard on how to make sure that users pick a unique username. I have two levels of membership. For the free membership, a user is created, capturing the first and last names plus email. Later on, when the user upgrades, I let them select a username, but I want to add a constraint that it be unique. I tried to do a search for users with a constraint where username does not equal current user’s username doing a conditional, but it doesn’t work. I tried doing a count: 0, but still no joy. I’ve built the entire website over 3 1/2 months at70 hours per week and was able to get unstuck on my own a gazillion times, but this one, for the life of me, I can’t figure out without some external help. Thanks in advance.

Make sure you have a privacy rule to allow searches and see the username field for users who have upgraded or are upgrading.

1 Like

Do you have privacy rules setup that’s stopping the return? Make the username public

I’ll try it when I’m at my machine tomorrow, it’s the middle of the night now, thanks.

That’s not related to the privacy policy.
Here is what I did that I had hoped would work:
I tried to disable the “Continue” button in the Upgrade Membership page by adding the following conditional:
Do a search for User
Add the constraint:
public_username <> Current User’s public_username

When Search for Users :count is equal or greater than 0 This element isn’t clickable.

And it’s not working.

In the end, all I’m trying to achieve is to make it impossible for a user to choose a username that already exists. You’d think that this question would have already been asked. Nope. Couldn’t fing it in the forum, nor on Youtube. It’s the only thing I haven’t been able to figure out in a site of comparable complexity to Airbnb.

It’s not really a complex issue, pretty basic which Is likely why you couldn’t find anything.

Reverse it, stay on the same account you’re testing with and drop a RG of users usernames on a blank page.see what gets returned. If you’re not getting all the usernames it’s a privacy issue.

If you are getting all users usernames then your issue is likely in your expression or setup.

1 Like

Exactly, I need help with the expression. I’ll ask support at this point, thanks.

Create a small transparent group on page, add a search for a user by their username using the value from the username field (you can use the live text plugin if you need it to search in real time), then set the group to yes/no and the expression should be “search for users:count > 0”

You can then reference that group in conditionals and on the workflow triggered by the user trying to lock in their username, to ensure they can’t select and know that it is already taken.

By using this approach, you only have to make the search one time and can reference from anywhere on the page.

I just saw this. I was off Bubble for several weeks as I was being a caregiver to a loved one who got surgery. Thank you so much for replying. I’ll have to give it a go soon. Right now, it’s pretty close to sounding like Chinese to me, but I’ll search every item I don’t get and see if I come out the other end. I was able to build the entire website with a few rather complex components, and was always able to figure it out – often times thanks to a YouTube video bailing me out – but that one issue has been a baffler. I’ll report back.

This search should be as simple as do a search for users:count < 1. In that search you’ll have two constraints. The first will be public_username = current user's public_username (if the user has a public_username already; otherwise, you’ll reference an Input’s value). Your second constraint will be unique id <> current user's unique id. If yes, they can upgrade, if not, they need to change their username.

The reason why we use :count < 1 instead of :count is 0 is because of the cost of Workload Units. Doing the former is more cost-efficient.


In the end, all I’m trying to achieve is to make it impossible for a user to choose a username that already exists. You’d think that this question would have already been asked. Nope. Couldn’t fing it in the forum, nor on Youtube.

Sure, this question has been asked multiple times, with different possible solutions suggested. :wink:
https://www.google.com/search?q=bubble.io+forum+unique+usernames&oq=bubble.io+forum+unique+usernames&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg8MgYIAhBFGDzSAQg1MTQyajBqN6gCALACAA&sourceid=chrome&ie=UTF-8

This topic was automatically closed after 70 days. New replies are no longer allowed.