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
preguntada hace 3 meses97 visualizaciones
2 Respuestas
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
EXPERTO
respondido hace 3 meses
  • 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
respondido hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas