我有一个通过 SAML 进行身份验证的网站。 我在这个网站上使用
aws-amplify
库。aws-amplify
v5 并编写了以下代码:
Auth.currentAuthenticatedUser().then(cognitoUser => {
...
}).catch(e => {
console.log(e);
window.location.href = this.redirectLink;
});
当用户被识别时 - 他到达了
then
内的部分,catch
的部分。
现在我正在尝试升级到v6, 我看到 here
currentAuthenticatedUser
函数已被弃用。getCurrentUser
和 fetchAuthSession
API。
我尝试同时使用两者和单独使用它们, 但我无法达到检测用户是否已被识别的程度。
getCurrentUser
函数总是落入catch
并出现错误“UserUnAuthenticatedException:用户需要经过身份验证才能调用此API。”fetchAuthSession
函数始终返回空属性。
我正在尝试弄清楚,
我是不是做错了什么?
我是不是错过了什么?
还是这个版本真的没有办法知道用户是否被识别?
提前致谢。
最后,
我是这样做的:
getCurrentUser().then(currentUser => {
fetchAuthSession().then(cognitoUserSession => {
this.doSomething(currentUser, cognitoUserSession);
});
})
.catch(e => {
signInWithRedirect({
provider: { custom: "myIdentityProvider" }
})
});