Amplify Gen 2, fullname userAttributes not present on sign up

0

Hi,

Add userAttributes on signup in amplify/auth/resource.ts:

export const auth = defineAuth({
  loginWith: {
    email: true
  },
  userAttributes: {
    // require the attribute be provided during sign-up
    preferredUsername: {
      required: true
    },
    // do not allow changing of an attribute's value
    birthdate: {
      mutable: false
    }
  }
});

Then in console:

npx amplify sandbox

Then it's OK:

preferredUsername

But then, just replacing preferredUsername by fullname in amplify/auth/resource.ts and and launching a new sandbox after deleting the previous one:

export const auth = defineAuth({
  loginWith: {
    email: true
  },
  userAttributes: {
    // require the attribute be provided during sign-up
    fullname: {
      required: true
    },
    // do not allow changing of an attribute's value
    birthdate: {
      mutable: false
    }
  }
});

fullname

od
질문됨 3달 전97회 조회
2개 답변
0

The problem arises from the fact that fullname is not recognized as a valid userAttribute. This is because AWS follows the standard set by the OpenID Connect specification, which assigns all users a predefined set of attributes.

The standard attributes available for Amplify are:

  • address
  • birthdate
  • email
  • family_name
  • gender
  • given_name
  • locale
  • middle_name
  • name
  • nickname
  • phone_number
  • picture
  • preferred_username
  • profile
  • sub
  • updated_at
  • website
  • zoneinfo
profile picture
전문가
답변함 3달 전
  • Ok then I try with 'name' in amplify/auth/resource.ts and I've got error "'name' does not exist in type 'StandardAttributes'":

    userAttributes: { // require the attribute be provided during sign-up name: { required: true, mutable: true }, }

    and if if I try npx amplify sandbox, error "TypeScript validation check failed, check your backend definition"

  • Also I know you wanted to use an attribute called "fullname", but the backend authentication resource authored using defineAuth does not currently support adding custom attributes. If you wish to add custom attributes you will need to define them using overrides.

    // amplify/backend.ts
    import { defineBackend } from '@aws-amplify/backend';
    import { auth } from './auth/resource.js';
    import { data } from './data/resource.js';
    
    const backend = defineBackend({
      auth,
      data
    });
    
    // extract L1 CfnUserPool resources
    const { cfnUserPool } = backend.auth.resources.cfnResources;
    // use CDK's `addPropertyOverride` to modify properties directly
    cfnUserPool.addPropertyOverride("Schema", [
      {
        Name: "publicName",
        AttributeDataType: "String",
        Mutable: true,
      },
    ]);
  • That weird, I was checking the documentation for Amplify Gen 2, name exists in the type StandardAttribute. Let's try this:

    export const auth = defineAuth({
      loginWith: {
        email: true
      },
      userAttributes: {
        // require the attribute be provided during sign-up
        name: {
          required: true
        },
        nickname: {
          required: true
        },
        given_name: {
          required: true
        },
        // do not allow changing of an attribute's value
        birthdate: {
          mutable: false
        }
      }
    });

    can you share your amplify/auth/resource.ts?

  • And as you mentionned before 'name' is part of OpenID Connect specification.

    I don't want fullName.. I just want 'name', I've only tried with fullName because name alone was causing touble, but my goal here is simply to have name.

    Here is my amplify/auth/resource.ts:

    import {defineAuth} from '@aws-amplify/backend';
    
    export const auth = defineAuth({
        loginWith: {
            email: true
        },
        userAttributes: {
            // require the attribute be provided during sign-up
            name: {
                required: true,
                mutable: true
            },
        }
    });
    
0

So, even if 'name' is part of OpenID specs and doesn't work for unknown reason, for now I'll use given name and family name, like below, instead:

import {defineAuth} from '@aws-amplify/backend';

export const auth = defineAuth({
    loginWith: {
        email: true
    },
    userAttributes: {
        // require the attribute be provided during sign-up
        givenName: {    // Given name or first name
            required: true,
            mutable: true
        },
        familyName: {
            required: true,
            mutable: true
        },
    }
});
od
답변함 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인