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

问题描述

因此,我试图按照文档中的指南进行操作,并且被困在这里

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...