amazon-s3 - 在哪里以及如何使用 AWS Amplify 获取 `identityId`?

标签 amazon-s3 amazon-cognito 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 首次登录功能。 后来当我想从 Storage 查询用户图像时:

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

关于amazon-s3 - 在哪里以及如何使用 AWS Amplify 获取 `identityId`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63356149/

相关文章:

amazon-web-services - AWS DataSync 无法检测到源 NFS 文件系统中的任何文件

amazon-s3 - 有效地将许多小文件移动到 Amazon S3

authentication - 使用 AWS Cognito 登录的最佳方法

javascript - AWS Amplify 登录 `currentAuthenticatedUser` 在登录后返回 `User is not authenticated`

javascript - 如何使用 Cognito 身份池和 Amplify 连接到 AWS AppSync

javascript - 如何管理使用 AWS Amplify Authentication 创建的用户

python - 列出 S3 对象直到第一级

java - AWS无法计算MD5哈希Android

amazon-web-services - 通过链接 API key 、使用计划和 Cognito 构建可计费的 API

ios - 获取 AWSAccountID