【问题标题】:Where and how to get `identityId` using AWS Amplify?使用 AWS Amplify 在哪里以及如何获取“identityId”?
【发布时间】:2020-11-30 23:59:28
【问题描述】:

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

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

如何获得identityId

【问题讨论】:

    标签: amazon-s3 amazon-cognito aws-amplify


    【解决方案1】:

    我通过将identityId 保存到成功用户登录时的自定义属性,从Auth.currentUserCredentials() 发现了一个破解方法:

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-30
      • 2021-09-01
      • 2020-07-10
      • 2013-07-07
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      • 2016-09-24
      相关资源
      最近更新 更多