所以我试图按照文档中的指南进行操作,但我被困在这里
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/