我尝试使用 AWS Amplify API currentAuthenticatedUser
获取经过身份验证的用户详细信息,但收到用户未经过身份验证
。
这是代码:
import { useRouter } from 'next/router'
import { Auth } from 'aws-amplify';
import { useForm } from "react-hook-form";
export default function SignIn({ setStatus }) {
const { register, handleSubmit } = useForm();
const router = useRouter()
async function signIn({ username, password }) {
try {
let signObj = await Auth.signIn(username, password); // returns the result
let userInfo = await Auth.currentAuthenticatedUser(); // returns User is not authenticated
} catch (error) {
console.log('error signing in', error);
}
}
return (
<h2></h2>
)
}
signIn
API 返回结果,但 currentAuthenticatedUser
返回用户未经过身份验证
。有什么想法可能会发生这种情况吗?
最佳答案
我通过在组件顶部导入我的身份验证配置来解决此问题
Amplify.configure({ Auth : {your auth config goes here }})
关于javascript - AWS Amplify 登录 `currentAuthenticatedUser` 在登录后返回 `User is not authenticated`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71998432/