{"record":{"id":"33ca3032a3bb670d","repo":"payloadcms/payload","slug":"a-user-with-the-given-email-is-already-registered","errorCode":null,"errorMessage":"A user with the given email is already registered.","messagePattern":"A user with the given email is already registered\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/auth/strategies/local/register.ts","lineNumber":68,"sourceCode":"      whereConstraint.or?.push({\n        username: {\n          equals: doc.username,\n        },\n      })\n    }\n  }\n\n  const existingUser = await payload.find({\n    collection: collection.slug,\n    depth: 0,\n    limit: 1,\n    pagination: false,\n    req,\n    where: whereConstraint,\n  })\n\n  if (existingUser.docs.length > 0) {\n    throw new ValidationError({\n      collection: collection.slug,\n      errors: [\n        canLoginWithUsername\n          ? {\n              message: req.t('error:usernameAlreadyRegistered'),\n              path: 'username',\n            }\n          : { message: req.t('error:userEmailAlreadyRegistered'), path: 'email' },\n      ],\n    })\n  }\n\n  const { hash, salt } = await generatePasswordSaltHash({ collection, password, req })\n\n  const sanitizedDoc = { ...doc }\n  if (sanitizedDoc.password) {\n    delete sanitizedDoc.password\n  }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/auth/strategies/local/register.ts#L50-L86","documentation":"Same `registerLocalStrategy` check, but fires when `canLoginWithUsername` is false (standard email auth). Throws a `ValidationError` with the localized `userEmailAlreadyRegistered` message on the `email` path when an existing user matches the email.","triggerScenarios":"Registering with an email that already exists in an email-login auth collection.","commonSituations":"Duplicate signup with the same email; re-running seeders; email column lacking a DB-level unique constraint.","solutions":["Use a unique email.","Pre-check email existence with `payload.find`.","Add a DB unique index on the email column."],"exampleFix":"// before\nawait payload.create({ collection: 'users', data: { email: 'a@b.com', password, ... } })\n// after\nconst exists = await payload.find({ collection: 'users', limit: 1, pagination: false, where: { email: { equals: 'a@b.com' } } })\nif (exists.docs.length) throw new Error('email registered')\nawait payload.create({ collection: 'users', data: { email: 'a@b.com', password, ... } })","handlingStrategy":"try-catch","validationCode":"async function isEmailAvailable(payload, slug, email) {\n  const res = await payload.find({ collection: slug, limit: 1, pagination: false, where: { email: { equals: email } } })\n  return res.docs.length === 0\n}","typeGuard":"function isValidationError(e): e is ValidationError {\n  return e?.name === 'ValidationError' && Array.isArray(e?.data?.errors)\n}","tryCatchPattern":"try {\n  await payload.create({ collection: 'users', data })\n} catch (e) {\n  if (isValidationError(e) && e.data.errors.some(x => x.path === 'email')) {\n    setFieldError('email', 'already registered')\n  } else throw e\n}","preventionTips":["Pre-check email and enforce DB uniqueness.","Map the `ValidationError` to the email field on the form."],"tags":["auth","register","validation","email","duplicate"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}