In most chat apps, it's essential to be able to tell the difference between users. Though the user ids are always different, by default Stream Chat allows users to have the same name for display. This can be an issue since a user could impersonate another or choose the same name by coincidence, causing confusion.
To help with this possible issue, we've introduced a new app setting called enforce_unique_usernames
. By using this new setting, you can block users from having the same username within the whole app or within a team if your app is multi-tenant. Any attempts to use an existing username will result in a duplicate username error.
When this setting is enabled, it won't affect existing users with duplicate usernames. Also, before checking if two usernames are equal, the system will first convert them to lower case and remove white spaces as well as other special characters. That means "John Doe" is considered a duplicate of "john doe", "john.doe", etc.
Within The App
To enforce unique usernames within the whole app, set the app setting enforce_unique_usernames
to "app" like below.
// Enable uniqueness constraints on App level await client.updateAppSettings({ enforce_unique_usernames: 'app', });
Within Teams
To enforce unique usernames only within each team, set the app setting enforce_unique_usernames
to "team" like below. Please note this setting only makes sense if your app is multi-tenant.
// Enable uniqueness constraints on Team level await client.updateAppSettings({ enforce_unique_usernames: 'team', });
We're happy to bring yet another feature to help Stream Chat fit your app's requirements. For more information about this new feature, see the documentation on unique usernames. If you need help or have specific feedback about this feature, please leave a comment on the documentation page.