aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
141 stars 45 forks source link

native support for custom attributes on auth #1541

Open ykethan opened 1 month ago

ykethan commented 1 month ago

Environment information

System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M1
  Memory: 210.19 MB / 16.00 GB
  Shell: /opt/homebrew/bin/fish
Binaries:
  Node: 20.11.1 - ~/.local/share/nvm/v20.11.1/bin/node
  Yarn: 1.22.19 - ~/.local/share/nvm/v20.11.1/bin/yarn
  npm: 10.2.4 - ~/.local/share/nvm/v20.11.1/bin/npm
  pnpm: 8.15.4 - ~/Library/pnpm/pnpm
NPM Packages:
  @aws-amplify/backend: 1.0.2
  @aws-amplify/backend-cli: 1.0.3
  aws-amplify: 6.3.2
  aws-cdk: 2.141.0
  aws-cdk-lib: 2.141.0
  typescript: 5.4.5
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

Followup on issue: https://github.com/aws-amplify/amplify-backend/issues/1511

we currently need to modify the cfnUserPool schema to add a custom property on the backend. would be great if we could add this on defineAuth directly.

josefaidt commented 1 month ago

marking as a feature request

josefaidt commented 1 month ago

we could do something like

import { defineAuth } from "@aws-amplify/backend"

export const auth = defineAuth({
  loginWith: {
    email: true,
  },
  userAttributes: {
    "custom:favorite_color": {
      required: true,
    },
  },
})
ataylorme commented 1 week ago

The AWS CDK Congito user pool takes separate parameters for standardAttributes and customAttributes.

I think there are a few approaches that might be easier than allowing user attribute keys prefixed with custom:

  1. Allow a user attributes key custom that is an object of user attributes. This is how the AttributeMapping interface in CDK does it for identity providers

Example:

const userAttributes = {
  email: {
    required: true,
    mutable: true,
  },
  custom: {
    myCustomAttribute: {
      required: false,
      mutable: true,
    },
  },
}
  1. Create a separate, optional auth prop for customAttributes that then gets passed directly to the CDK prop for custom attributes

@josefaidt if you are open to either of these I can work on a PR.