Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preferred_username is required but cant be set during registration. #13724

Closed
3 tasks done
daskabe opened this issue Aug 18, 2024 · 4 comments
Closed
3 tasks done

preferred_username is required but cant be set during registration. #13724

daskabe opened this issue Aug 18, 2024 · 4 comments
Assignees
Labels
Auth Related to Auth components/category documentation Related to documentation feature requests Gen 2 Issues related to Gen 2 Amplify projects

Comments

@daskabe
Copy link

daskabe commented Aug 18, 2024

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

CDK

Environment information

# Put output below this line
 System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 105.63 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
    pnpm: 8.15.5 - ~/.nvm/versions/node/v18.19.0/bin/pnpm
  Browsers:
    Brave Browser: 127.1.68.137
    Chrome: 127.0.6533.120
    Safari: 17.4.1
  npmPackages:
    @eslint/js: ^9.8.0 => 9.9.0 
    @hookform/resolvers: ^3.9.0 => 3.9.0 
    @hookform/resolvers/ajv:  1.0.0 
    @hookform/resolvers/arktype:  2.0.0 
    @hookform/resolvers/class-validator:  1.0.0 
    @hookform/resolvers/computed-types:  1.0.0 
    @hookform/resolvers/effect-ts:  1.0.0 
    @hookform/resolvers/fluentvalidation-ts:  1.0.0 
    @hookform/resolvers/io-ts:  1.0.0 
    @hookform/resolvers/joi:  1.0.0 
    @hookform/resolvers/nope:  1.0.0 
    @hookform/resolvers/superstruct:  1.0.0 
    @hookform/resolvers/typanion:  1.0.0 
    @hookform/resolvers/typebox:  1.0.0 
    @hookform/resolvers/typeschema:  1.0.0 
    @hookform/resolvers/valibot:  1.0.0 
    @hookform/resolvers/vest:  1.0.0 
    @hookform/resolvers/vine:  1.0.0 
    @hookform/resolvers/yup:  1.0.0 
    @hookform/resolvers/zod:  1.0.0 
    @radix-ui/colors: ^3.0.0 => 3.0.0 
    @radix-ui/react-icons: ^1.3.0 => 1.3.0 
    @radix-ui/react-toolbar: ^1.1.0 => 1.1.0 
    @radix-ui/themes: ^3.1.1 => 3.1.3 
    @types/react: ^18.3.3 => 18.3.3 
    @types/react-dom: ^18.3.0 => 18.3.0 
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    aws-amplify: ^6.5.1 => 6.5.1 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    eslint: ^9.8.0 => 9.9.0 
    eslint-plugin-react-hooks: ^5.1.0-rc.0 => 5.1.0-rc-fb9a90fa48-20240614 
    eslint-plugin-react-refresh: ^0.4.9 => 0.4.9 
    globals: ^15.9.0 => 15.9.0 (11.12.0, 14.0.0)
    isomorphic-dompurify: ^2.14.0 => 2.14.0 
    marked: ^14.0.0 => 14.0.0 
    react: ^18.3.1 => 18.3.1 
    react-dom: ^18.3.1 => 18.3.1 
    react-favicon: ^2.0.7 => 2.0.7 
    react-hook-form: ^7.52.2 => 7.52.2 
    react-router-dom: ^6.25.1 => 6.26.0 
    typescript: ^5.5.3 => 5.5.4 
    typescript-eslint: ^8.0.0 => 8.1.0 
    vite: ^5.4.0 => 5.4.0 
    web-vitals: ^4.2.3 => 4.2.3 
    zod: ^3.23.8 => 3.23.8 
  npmGlobalPackages:
    aws-cdk: 2.150.0
    corepack: 0.22.0
    firebase-tools: 13.4.0
    npm: 10.2.3
    pino-pretty: 11.0.0
    pnpm: 8.15.5
    semver: 7.6.3
    typescript: 5.3.3

Describe the bug

preferred_username should not be a Required attribute IF it cant be set during user sign up flow.

Expected behavior

preferred_username should not be required field. if it is - it should be settable during signup.

image
const user = await signUp({
      username:email,
      password,
      options: {
        userAttributes: {
          name: fullName,
          phone_number: formatPhoneNumber(phoneNumber),
          email,
          preferred_username: username,
          updated_at: Date.now().toString(),
        },
      },
    });

the above code gives this error:

image

Reproduction steps

Create a userpool with preferred_username as required field and then try to create a user.

If this is system limitation then userpool creation should fail if preferred_username is set as required field.

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@daskabe daskabe added the pending-triage Issue is pending triage label Aug 18, 2024
@cwomack cwomack added the Auth Related to Auth components/category label Aug 19, 2024
@cwomack cwomack self-assigned this Aug 19, 2024
@cwomack
Copy link
Member

cwomack commented Aug 19, 2024

Hello, @daskabe is your preferred username set up as required and as an alias? Per the Cognito docs here, it can be one but not both.

@cwomack cwomack added question General question pending-response Gen 2 Issues related to Gen 2 Amplify projects and removed pending-triage Issue is pending triage labels Aug 19, 2024
@israx
Copy link
Member

israx commented Aug 21, 2024

Hello @daskabe. This seems to be a Cognito bug. You are right, the creation of the userpool should fail when preferred_username is selected as a required attribute.

You would need to create another userpool without the preferred_username as a require attribute and then call the updateUserAttribute API upon authentication and add a preferred_username

@daskabe
Copy link
Author

daskabe commented Aug 22, 2024

thats what i ended up doing to move forward with my development - created another userpool - But now my users cant sign in using their username. Currently just using email. I didn't bather setting preferred_username ; instead i saved the username to custom:username attribute during signup to hopefully validate that somehow during sign up.

And how/why is account confirmation status related to a preferred_username? preferred_username is just attribute and does not need confirmation.

This is what i would want to see.

  1. if user has all 3 selected in the following image, then preferred_username should be settable field during sign up

  2. dont call it User name as its confusing; call it userHandle
    because if you ask frontend engineer, username can be : email || phone || userHandle(eg elonMusk)

  3. the signUp(...) function should just take object of attributes(some of which can be required based on user pool configuration), So no username, password and options.userAttributes fields. Because right now i am confused what username:{email} is actually accomplishing if my use case is: my users login using phone numbers.
    But if i just send an object with all required and custom attributes; congito should just work based on how its configured during creation.

  4. this section is redundant

If you select only phone number and email, your user will be prompted to select one of the two sign-in options when they sign up.

Cognito signIn(...) process should parse and validate the provided username - (one of email || phone || userHandle) and then perform login action...no need to force user to select the preferred way. Imagine having your email as preferred way but then you lose your email...how do you login and change your preference? Ideally i should be able to login with all my 3 options anytime (the userPool is configured to accept all 3)

image

@israx

@cwomack cwomack added documentation Related to documentation feature requests and removed question General question labels Aug 27, 2024
@cwomack
Copy link
Member

cwomack commented Sep 6, 2024

@daskabe, closing this issue as it will be captured as a docs improvement in the above referenced amplify-docs issue. You can track the progress there, but I'll leave another comment on here once the updates are merged in. Thanks!

@cwomack cwomack closed this as completed Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category documentation Related to documentation feature requests Gen 2 Issues related to Gen 2 Amplify projects
Projects
None yet
Development

No branches or pull requests

3 participants