mattermost-community/focalboard · error
The username already exists
Error message
The username already exists
What it means
RegisterUser returns this when a user with the requested username already exists (the uniqueness-check branch that runs when a guest/username must be unique). The store lookup found an existing user with that name.
Source
Thrown at server/app/auth.go:156
return errors.Wrap(err, "unable to delete the session")
}
a.metrics.IncrementLogoutCount(1)
return nil
}
// RegisterUser creates a new user if the provided data is valid.
func (a *App) RegisterUser(username, email, password string) error {
var user *model.User
if username != "" {
var err error
user, err = a.store.GetUserByUsername(username)
if err != nil && !model.IsErrNotFound(err) {
return err
}
if user != nil {
return errors.New("The username already exists")
}
}
if user == nil && email != "" {
var err error
user, err = a.store.GetUserByEmail(email)
if err != nil && !model.IsErrNotFound(err) {
return err
}
if user != nil {
return errors.New("The email already exists")
}
}
// TODO: Move this into the config
passwordSettings := auth.PasswordSettings{
MinimumLength: 6,
}View on GitHub (pinned to a84bbb65e3)
Solutions
- Pick a different username
- Check existing users first and surface a friendly conflict message before registering
- If re-registering intentionally, look up and reuse the existing user instead
Example fix
// before
err := app.RegisterUser(email, username, password)
// after
if u, _ := app.Store.GetUserByUsername(username); u != nil {
return fmt.Errorf("username %q is taken, choose another", username)
}
err := app.RegisterUser(email, username, password) Defensive patterns
Strategy: validation
Validate before calling
if existing, err := store.GetUserByUsername(username); err == nil && existing != nil {
return fmt.Errorf("username %q already taken", username)
} Type guard
func usernameTaken(u *model.User) bool { return u != nil } Try / catch
err := a.RegisterUser(email, username, password)
if err != nil {
if strings.Contains(err.Error(), "already exists") {
return ErrUsernameTaken
}
return errors.Wrap(err, "registration failed")
} Prevention
- Pre-check username availability in the UI before submit
- Normalize username case before uniqueness checks
- In imports, dedupe and map colliding usernames first
When it happens
Trigger: a.RegisterUser(email, username, ...) where store.GetUserByUsername(username) returns a non-nil user in the uniqueness-check path (e.g. adding a guest whose username collides).
Common situations: Duplicate signup attempts with a taken handle; importing users whose usernames collide with existing accounts; case-sensitivity differences between check and store.
Related errors
AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30).
Data as JSON: /api/errors/ac8d70195ea83674.
Report an issue: GitHub.