{"record":{"id":"8ca395de1e03fe1c","repo":"anomalyco/sst","slug":"you-cannot-set-both-aliases-and-usernames-learn-m","errorCode":null,"errorMessage":"You cannot set both aliases and usernames. Learn more about customizing sign-in attributes at https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases","messagePattern":"You cannot set both aliases and usernames\\. Learn more about customizing sign-in attributes at https://docs\\.aws\\.amazon\\.com/cognito/latest/developerguide/user-pool-settings-attributes\\.html#user-pool-settings-aliases","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/cognito-user-pool.ts","lineNumber":630,"sourceCode":"    const userPool = createUserPool();\n\n    const domain = normalizeDomain();\n    const certificateArn = createSsl();\n    const cognitoDomain = createCognitoDomain();\n    createDnsRecords();\n\n    this.constructorOpts = opts;\n    this.userPool = userPool;\n    this._domainUrl = domain?.apply((d) =>\n      d.prefix\n        ? interpolate`https://${d.prefix}.auth.${region}.amazoncognito.com`\n        : interpolate`https://${d.name}`,\n    );\n\n    function normalizeAliasesAndUsernames() {\n      all([args.aliases, args.usernames]).apply(([aliases, usernames]) => {\n        if (aliases && usernames)\n          throw new VisibleError(\n            \"You cannot set both aliases and usernames. Learn more about customizing sign-in attributes at https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases\",\n          );\n      });\n    }\n\n    function normalizeTriggers() {\n      if (!args.triggers) return;\n\n      return output(args.triggers).apply((triggers) => {\n        if (\n          (triggers.customEmailSender || triggers.customSmsSender) &&\n          !triggers.kmsKey\n        )\n          throw new VisibleError(\n            \"You must provide a KMS key via `kmsKey` when configuring `customEmailSender` or `customSmsSender`.\",\n          );\n\n        return {","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/cognito-user-pool.ts#L612-L648","documentation":"In Cognito, a user pool uses either alias attributes (email/phone/preferred_username re-assignable identifiers) or explicit username attributes — not both. SST surfaces this Cognito constraint as a VisibleError when both args.aliases and args.usernames are set.","triggerScenarios":"new sst.aws.CognitoUserPool('X', { aliases: [...], usernames: [...] }) — normalizeAliasesAndUsernames applies both args and throws when both are truthy.","commonSituations":"Extending an existing pool config that used usernames by also adding aliases for social sign-in; merging configs from two examples; misunderstanding Cognito's alias-vs-username semantics.","solutions":["Remove args.usernames and keep args.aliases (recommended for flexible sign-in identifiers).","Or remove args.aliases if you specifically need fixed username attributes.","Decide based on sign-in model: aliases allow multiple identifiers per user; usernames are immutable.","Note this cannot be changed after a pool is created — plan before first deploy."],"exampleFix":"// before\nnew sst.aws.CognitoUserPool('MyPool', {\n  aliases: ['email', 'preferred_username'],\n  usernames: ['email']\n});\n// after\nnew sst.aws.CognitoUserPool('MyPool', {\n  aliases: ['email', 'preferred_username']\n});","handlingStrategy":"validation","validationCode":"function validateUserPoolIdentity(poolArgs) {\n  if (poolArgs.aliases && poolArgs.usernames)\n    throw new Error('Choose either aliases or usernames, not both');\n}\nvalidateUserPoolIdentity({ aliases: ['email'] });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide the sign-in model (aliases vs usernames) before first deploy; it's immutable per pool.","Default to aliases for flexible identifiers.","Document the choice in your infra config comments."],"tags":["aws","cognito","authentication","mutually-exclusive","config-validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}