email and password login, with unique username

Hey, is it possible to enforce unique usernames with email and password login? I want it to error if the username they chose is already taken, similar to how it works with emial.
const response = await authClient.signUp.email({
email: data.email,
password: data.password,
name: data.username,
});
const response = await authClient.signUp.email({
email: data.email,
password: data.password,
name: data.username,
});
emailAndPassword: {
enabled: true,
},
emailAndPassword: {
enabled: true,
},
5 Replies
LightTab2
LightTab27d ago
Isn't there username field and name is only for displayed name? Let me check the docs... name is supposed to be a user real name, if you need to process such data, there is a displayUsername for display and username which I am pretty sure is unique in DB, but docs don't state that And the login in api by username() plugin needs username not name @Better Auth Is username in username plugin unique?
Better Auth
Better Auth7d ago
The username plugin is designed so that the username field is marked as unique in the schema (it has the unique flag set) [6]. However, there has been a reported issue where this uniqueness isn’t enforced at the application level during sign-up—resulting in duplicate usernames being stored if no additional checking is implemented [1]. In short, while the intent is for usernames to be unique, you might need to add an extra layer of validation or check for updates if uniqueness is a critical requirement for your application. Sources: [1] Username plugin doesn't ensure username uniqueness [6] Username | Better Auth — Better Auth is powered by https://clarm.com
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
Username plugin doesn't ensure username uniqueness · Issue #866 ·...
Describe the bug Adding the username plugin doesn't ensure the username uniqueness at application level, although it should. To Reproduce Steps to reproduce the behavior: Setup a register form ...
Username | Better Auth
Username plugin
Clarm
Automate customer support with AI for developer, finance, and technical teams
LightTab2
LightTab27d ago
@Better Auth The issue was closed, is there any open issue regarding this?
Better Auth
Better Auth7d ago
Hi there! Based on our current records, it looks like the issue you mentioned has been resolved and closed. There aren’t any open issues tracking that exact problem at the moment [e.g., Document 1 and others show that similar issues have been addressed]. Could you let me know if you meant a specific aspect or have additional details? That way, I can help verify if anything related is still under discussion. — Better Auth is powered by https://clarm.com
Clarm
Automate customer support with AI for developer, finance, and technical teams
v28
v28OP7d ago
cool! thank you 🙂

Did you find this page helpful?