feat(username): Check username availability (#3025)

* feat(username): Check username availability

closes https://github.com/better-auth/better-auth/issues/1553

* add: docs
This commit is contained in:
Maxwell
2025-06-16 17:24:57 +10:00
committed by GitHub
parent 93d5bbe04d
commit be3face70c
3 changed files with 67 additions and 0 deletions

View File

@@ -96,6 +96,23 @@ const data = await authClient.updateUser({
})
```
### Check if username is available
To check if a username is available, you can use the `isUsernameAvailable` function provided by the client.
```ts title="auth-client.ts"
const response = await authClient.isUsernameAvailable({
username: "new-username"
});
if(response.data?.available) {
console.log("Username is available");
} else {
console.log("Username is not available");
}
```
## Schema
The plugin requires 1 field to be added to the user table: