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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン