{"record":{"id":"73d7e73f6b68d3f4","repo":"mattermost-community/focalboard","slug":"the-email-already-exists","errorCode":null,"errorMessage":"The email already exists","messagePattern":"The email already exists","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/app/auth.go","lineNumber":167,"sourceCode":"\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}\n\n\terr := auth.IsPasswordValid(password, passwordSettings)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"Invalid password\")\n\t}\n\n\t_, err = a.store.CreateUser(&model.User{\n\t\tID:          utils.NewID(utils.IDTypeUser),\n\t\tUsername:    username,\n\t\tEmail:       email,\n\t\tPassword:    auth.HashPassword(password),","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/app/auth.go#L149-L185","documentation":"RegisterUser returns this when a user with the requested email already exists. The store lookup by email found a live record, so registration is refused to keep emails unique.","triggerScenarios":"a.RegisterUser(email, ...) with a non-empty email where store.GetUserByEmail(email) returns an existing user.","commonSituations":"Second signup with the same email; re-inviting an already-registered member; import data containing emails of existing users; dev DBs copied between environments.","solutions":["Use a different email address","Detect the existing account and send a 'you already have an account' / login link instead of registering","Pre-check with store.GetUserByEmail and handle ModelErrNotFound before calling"],"exampleFix":"// before\nerr := app.RegisterUser(sameEmail, name, password)\n// after\nif existing, _ := app.Store.GetUserByEmail(sameEmail); existing != nil {\n    return errors.New(\"an account with this email already exists; please log in\")\n}\nerr := app.RegisterUser(sameEmail, name, password)","handlingStrategy":"validation","validationCode":"if existing, err := store.GetUserByEmail(email); err == nil && existing != nil {\n    return fmt.Errorf(\"an account with email %s already exists\", email)\n}","typeGuard":"func emailTaken(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 ErrEmailTaken\n    }\n    return errors.Wrap(err, \"registration failed\")\n}","preventionTips":["Pre-check email availability before submitting registration","Use model.IsErrNotFound(err) to distinguish 'not found' from real store errors","Normalize/trim email addresses (lowercase) before checking and storing"],"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"}