Reputation: 327
Using AWS Amplify to create an authentication (Cognito) with Reactjs, the default username is a UUID. So when I log in to the system I see:
Hello f725e4a2-1f24-487d-9265-864947f5c5eb
How do I change this behavior? There may be a way of changing this in the frontend, but I would like to change this in the backend, because the list of users in Cognito has UUIDs as the identifier as well. I would like to see email as username instead.
Thank you!
Upvotes: 2
Views: 6495
Reputation: 829
There is currently no way to update it after creating a user pool.
In the amplify folder, you will see a folder awscloudformation, and this contains a file "nested-cloudformation-stack.yml"
search for this "usernameAttributes" in the file and replace it with email rather then username
"usernameAttributes": "email",
Also, you can only set it before creating a cognito pool
Upvotes: 1
Reputation: 2106
You will have to create a new userpool because you cant update such a setting after a pool has been created.
Go to the console and configure a new user pool directly on the web it will provide you with login with email option
And then update to your Auth config with the new userpool details.
Example from aws-amplify
import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito Federated Identity Pool Region
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// OPTIONAL - Configuration for cookie storage
// Note: if the secure flag is set to true, then the cookie transmission requires a secure protocol
cookieStorage: {
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - Cookie secure flag
// Either true or false, indicating if the cookie transmission requires a secure protocol (https).
secure: true
},
// OPTIONAL - customized storage object
storage: new MyStorage(),
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH'
}
});
// You can get the current config object
const currentConfig = Auth.configure();
Or update the aws-exports.js
file directly with the new pool details.
If your application is already live you might need to migrate your users.
How do I change the attributes of an Amazon Cognito user pool after creation will be a good guide
Upvotes: 3