Restrict username to user first name

AI-generated summary

In a support discussion titled ‘Restrict username to user first name,’ Celso_Teixeira explains that when users register via OpenID, Discourse auto-generates usernames based on full names — sometimes appending numbers if taken — but they want usernames to reflect only the user’s first name. Lilly notes this topic was previously raised here. Celso_Teixeira clarifies the goal and ongoing challenges. pfaffman suggests modifying the OpenID server to send the desired username via the preferred_nickname field, referencing a guide and source code. Arkshine offers a custom component that hides the username field and auto-generates it from the first name, though it previously required full_name_required and prioritize_username_in_ux settings (now struck through, suggesting they may no longer be needed). The thread combines configuration advice, code-level fixes, and plugin solutions to enforce first-name-only usernames during OpenID registration.

When users sign up on the forum using OpenID, their email and username get automatically filled and validated. If the chosen username is taken, Discourse adds a number to make it unique. The username is chosen based on the user name.

The issue is that we want the username to be only the user’s first name, not the full name. I’ve been trying to change the username during registration, but I haven’t found a successful way yet. Any suggestions on how to fix this would be appreciated.

you posted this already I think

Now it is more clear what I want to achieve, and the problems I’m facing

If you control the openID server then you should be able to have it send whatever you want to Discourse.

This might help:

Looks like you can populate preferred_nickname with the username you think you want. What are you sending in that field? If it’s empty or their full name, that would be a good first thing to change.

You can also try this component; this should do what you want in your context.

It hides the username field and generates its value based on the name field, extracting only the first name.

It expects the following settings enabled:

  • full_name_required
  • prioritize_username_in_ux

https://github.com/Arkshine/discourse-display-first-name-only