Hey guys! How do you manage your users in your se...
# help
b
Hey guys! How do you manage your users in your serverless app? I thought of using the key ‘sub’ from cognito “userPool” as a unique reference of my user, but it seems that it is boring to retrieve it when your API is protected via “IAM”.
Here what i’ve on
event.requestContext.authorizer
authorizer: {
iam: {
accessKey: 'xx',
accountId: 'xxx',
callerId: 'xx:CognitoIdentityCredentials',
cognitoIdentity: [xx],
principalOrgId: 'aws:PrincipalOrgID',
userArn: 'arn:aws:sts:xxxassumed-role/xxx',
userId:' xxx'
}
},
There is an
userId
, but don’t know if I can use it as unique reference of my user.
Seems legit to use userId after reading some articles.
f
I normally use
cognitoIdentity.identityId
as user id. What does the
userId
field look like?
b
userId:
AROAUSNGTDVHSN65TVIM4:CognitoIdentityCredentials
Hmm, it seems that the
userId
is not unique, my bad. I’ve two options: Identity Pool User Id or User Pool User Id 1. For Identity Pool User Id is simple because this one is provided on the request context. 2. For User Pool User Id is less trivial because, even though this one is provided too, I have to parse it.
If I understand well, if I want to enable the user to use multiple sources of logins, it’s better to use Identity Pool User Id because I can federate them and keep the same id.
f
Yup that’s correct 👍