AWS Cognito 允许开发者选择哪个属性(即参数)作为用户的主键,可以使用 email、phone_number 或自定义参数等。以下是使用 email 作为主键的示例代码:
var poolData = {
UserPoolId : 'YOUR_USER_POOL_ID',
ClientId : 'YOUR_APP_CLIENT_ID'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : 'user@example.com',
Pool : userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
// 其他操作...
在上面的代码中,email 被用作用户名(Username),也就是主键。使用其他属性作为主键同理,只需要修改相应地方即可。