Saman -
10/16/2021, 3:05 PMUsername - Users can use a username and optionally multiple alternatives to sign up and sign in.
I want to allow Users to sign in/out with both Username & Email. I want both these attributes to be required. How do I achieve this?
BR,
SamanSaman -
10/16/2021, 3:06 PMResources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
# Generate a name based on the stage
UserPoolName: ${self:provider.stage}-user-pool
# Set email as an alias
Policies:
PasswordPolicy:
MinimumLength: 8
RequireLowercase: false
RequireNumbers: false
RequireSymbols: false
RequireUppercase: false
Schema:
-
AttributeDataType: String
Mutable: true
Name: "image_url"
-
AttributeDataType: String
Mutable: true
Name: "username"
UsernameAttributes:
- email
AutoVerifiedAttributes:
- email
EmailConfiguration:
EmailSendingAccount: COGNITO_DEFAULT
Frank
preferred_username
instead of username
for actually Username. B/c username
cannot be changed.Frank
preferred_username
and email
, you’d want to set:
AliasAttributes:
- email
- preferred_username
Saman -
10/17/2021, 1:04 PMSaman -
10/17/2021, 4:05 PMAn error occurred: CognitoUserPool - Updates are not allowed for property - AliasAttributes. (Service: AWSCognitoIdentityProvider; Status Code: 400; Error Code: InvalidParameterException; Request ID: null; Proxy: null).
Frank
Saman -
10/18/2021, 1:26 PMNo export named develop-UserPoolId found.
My yml
# Print out the Id of the User Pool that is created
Outputs:
UserPoolId:
Value:
Ref: CognitoUserPool
Export:
Name: TrainoApp-${self:provider.stage}-UserPoolId
UserPoolClientId:
Value:
Ref: CognitoUserPoolClient
Export:
Name: TrainoApp-${self:provider.stage}-UserPoolClientId
Frank
${self:provider.stage}-UserPoolId
in your yml?Saman -
10/19/2021, 4:32 PMResources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
# Generate a name based on the stage
UserPoolName: ${self:provider.stage}-user-pool
# Set email as an alias
Policies:
PasswordPolicy:
MinimumLength: 8
RequireLowercase: false
RequireNumbers: false
RequireSymbols: false
RequireUppercase: false
Schema:
-
AttributeDataType: String
Mutable: true
Name: "image_url"
UsernameAttributes:
- email
- preferred_username
AutoVerifiedAttributes:
- email
- preferred_username
EmailConfiguration:
EmailSendingAccount: COGNITO_DEFAULT
CognitoUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
# Generate an app client name based on the stage
ClientName: ${self:provider.stage}-user-pool-client
UserPoolId:
Ref: CognitoUserPool
ExplicitAuthFlows:
- ADMIN_NO_SRP_AUTH
GenerateSecret: false
# Print out the Id of the User Pool that is created
Outputs:
UserPoolId:
Value:
Ref: CognitoUserPool
Export:
Name: ${self:provider.stage}-UserPoolId
UserPoolClientId:
Value:
Ref: CognitoUserPoolClient
Export:
Name: ${self:provider.stage}-UserPoolClientId
Saman -
10/19/2021, 4:32 PMisEmailBusy:
handler: handler/user/user.isEmailBusy
environment:
USER_POOL_ID: !ImportValue ${self:provider.stage}-UserPoolId
USER_POOL_CLIENT_ID: !ImportValue ${self:provider.stage}-UserPoolClientId
USER_POOL_PW: ${env:USER_POOL_PW}
USER_POOL_USER: ${env:USER_POOL_USER}
ACCESS_KEY_ID: ${env:ACCESS_KEY_ID}
SECRET_ACCESS_KEY: ${env:SECRET_ACCESS_KEY}
events:
- http:
method: POST
path: /isemailavailable
isUsernameBusy:
handler: handler/user/user.isUsernameBusy
environment:
USER_POOL_ID: !ImportValue ${self:provider.stage}-UserPoolId
USER_POOL_CLIENT_ID: !ImportValue ${self:provider.stage}-UserPoolClientId
USER_POOL_PW: ${env:USER_POOL_PW}
USER_POOL_USER: ${env:USER_POOL_USER}
ACCESS_KEY_ID: ${env:ACCESS_KEY_ID}
SECRET_ACCESS_KEY: ${env:SECRET_ACCESS_KEY}
events:
- http:
method: POST
path: /isusernameavailable
Saman -
10/19/2021, 4:33 PMFrank
!ImportValue ${self:provider.stage}-UserPoolId
the UserPoolId but it hasn’t been created.Frank
serverless.yml
?Saman -
10/20/2021, 6:54 AMSaman -
10/20/2021, 6:56 AMSaman -
10/20/2021, 7:15 PMSaman -
10/21/2021, 2:37 PMFrank
Ref
instead of ImportValue
b/c the former sets a inter-resource dependency so the User Pool will gets created first.Frank
Frank
serverless.yml
b/c you are writing raw CloudFormation. They are all taken care of out of the box with SST. 🤓Saman -
10/21/2021, 5:58 PM