使用 AWS Amplify 在何处以及如何获取“identityId”?

Where and how to get `identityId` using AWS Amplify?

所以我试图按照文档中的指南进行操作,但我被困在这里

Storage.get('test.txt', { 
  level: 'protected', 
  identityId: 'xxxxxxx' // the identityId of that user
})
.then(result => console.log(result))
.catch(err => console.log(err));

如何获得 identityId

我从 Auth.currentUserCredentials() 找到了破解方法,方法是在用户成功登录时将 identityId 保存到自定义属性:

const CUSTOM_IDENTITY_FIELD = "custom:identityId";

if (attributes && !attributes[CUSTOM_IDENTITY_FIELD]) {
    await Auth.updateUserAttributes(currUser, {
      [CUSTOM_IDENTITY_FIELD]: (await Auth.currentUserCredentials())
        .identityId,
    });
    onInfo("Welcome to Tippify, " + currUser.username);
}

有了这个,我还可以实现 Firebase first-time 登录功能。 后来想查询用户图片的时候 Storage:

Storage.get(user.picture, {
    level: "protected",
    identityId: user[CUSTOM_IDENTITY_FIELD],
})
  .then(setPicture)
  .catch(onError);