amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

native support for custom attributes on auth

Open ykethan opened this issue 1 year ago • 2 comments

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.

ykethan avatar May 21 '24 00:05 ykethan

marking as a feature request

josefaidt avatar May 21 '24 16:05 josefaidt

we could do something like

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

export const auth = defineAuth({
  loginWith: {
    email: true,
  },
  userAttributes: {
    "custom:favorite_color": {
      required: true,
    },
  },
})

josefaidt avatar May 23 '24 04:05 josefaidt

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.

ataylorme avatar Jun 24 '24 18:06 ataylorme

Hey @ataylorme :wave: sorry I missed this message! This is now available with @aws-amplify/[email protected]

closing

josefaidt avatar Jul 22 '24 22:07 josefaidt