{"record":{"id":"ac8d70195ea83674","repo":"mattermost-community/focalboard","slug":"the-username-already-exists","errorCode":null,"errorMessage":"The username already exists","messagePattern":"The username already exists","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/app/auth.go","lineNumber":156,"sourceCode":"\t\treturn errors.Wrap(err, \"unable to delete the session\")\n\t}\n\n\ta.metrics.IncrementLogoutCount(1)\n\n\treturn nil\n}\n\n// RegisterUser creates a new user if the provided data is valid.\nfunc (a *App) RegisterUser(username, email, password string) error {\n\tvar user *model.User\n\tif username != \"\" {\n\t\tvar err error\n\t\tuser, err = a.store.GetUserByUsername(username)\n\t\tif err != nil && !model.IsErrNotFound(err) {\n\t\t\treturn err\n\t\t}\n\t\tif user != nil {\n\t\t\treturn errors.New(\"The username already exists\")\n\t\t}\n\t}\n\n\tif user == nil && email != \"\" {\n\t\tvar err error\n\t\tuser, err = a.store.GetUserByEmail(email)\n\t\tif err != nil && !model.IsErrNotFound(err) {\n\t\t\treturn err\n\t\t}\n\t\tif user != nil {\n\t\t\treturn errors.New(\"The email already exists\")\n\t\t}\n\t}\n\n\t// TODO: Move this into the config\n\tpasswordSettings := auth.PasswordSettings{\n\t\tMinimumLength: 6,\n\t}","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/app/auth.go#L138-L174","documentation":"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.","triggerScenarios":"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).","commonSituations":"Duplicate signup attempts with a taken handle; importing users whose usernames collide with existing accounts; case-sensitivity differences between check and store.","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"],"exampleFix":"// before\nerr := app.RegisterUser(email, username, password)\n// after\nif u, _ := app.Store.GetUserByUsername(username); u != nil {\n    return fmt.Errorf(\"username %q is taken, choose another\", username)\n}\nerr := app.RegisterUser(email, username, password)","handlingStrategy":"validation","validationCode":"if existing, err := store.GetUserByUsername(username); err == nil && existing != nil {\n    return fmt.Errorf(\"username %q already taken\", username)\n}","typeGuard":"func usernameTaken(u *model.User) bool { return u != nil }","tryCatchPattern":"err := a.RegisterUser(email, username, password)\nif err != nil {\n    if strings.Contains(err.Error(), \"already exists\") {\n        return ErrUsernameTaken\n    }\n    return errors.Wrap(err, \"registration failed\")\n}","preventionTips":["Pre-check username availability in the UI before submit","Normalize username case before uniqueness checks","In imports, dedupe and map colliding usernames first"],"tags":["auth","registration","duplicate"],"backgroundTag":"duplicate-resource-conflict","analyzedSha":"a84bbb65e32edf972856b329417096ac413518e9","analyzedAt":"2026-08-30T09:22:20.720Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}