Amplify Javascript Auth客户端无法访问认证会话

0

【以下的问题经过翻译处理】 我正在使用 aws 示例中的代码 https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/#retrieve-current-authenticated-user在注册、登录后,我正在尝试 更新电子邮件。 一旦我调用更改电子邮件地址,我总是收到错误: "未捕获(承诺中)类型错误:user.getSession 不是一个 aws amplify auth 模块的函数。" 我试图找出问题所在? 下面的代码是它的使用顺序。 ''' async function signUp(username, password) { try { const { user } = await Auth.signUp({ username, password, attributes: { email: username//, // optional //phone_number, // optional - E.164 number convention // other custom attributes }, autoSignIn: { // optional - enables auto sign in after user is confirmed enabled: true, } }); console.log(user); console.log(currentAuthenticatedUserSession()); } catch (error) { console.log('error signing up:', error); } }

async function confirmSignUp(username, code) { try { await Auth.confirmSignUp(username, code); } catch (error) { console.log('error confirming sign up', error); } }

async function signIn(username, password) { try { const user = await Auth.signIn(username, password); user.Session=user.signInUserSession; console.log(user); } catch (error) { console.log('error signing in', error); } }

async function changeEmail(newEmail){ // Send confirmation code to user's old email // Calling this line here seems to not be passing the session as it errors out with the error posted in the beginning above. Auth.updateUserAttributes(currentAuthenticatedUserSession(), {'email':newEmail}) .then((data) => console.log(data)) .catch((err) => console.log(err)); }

//I have made several variations of this function, but nothing works. async function currentAuthenticatedUserSession(){ Auth.currentSession() .then((user) => { console.log(user); return user }) .catch((err) => console.log(err)); }

async function changeEmailComplete(code){ // Collect confirmation code and new email, then Auth.verifyCurrentUserAttributeSubmit('email', code) .then((data) => console.log(data)) .catch((err) => console.log(err)); } '''

1개 답변
0

【以下的回答经过翻译处理】 发现这个解决了问题:https://github.com/aws-amplify/amplify-js/issues/10108 并将changeEmail()更新为: ''' async function changeEmail(newEmail){ // Send confirmation code to user's old email const user = await Auth.currentAuthenticatedUser(); await Auth.updateUserAttributes(user, {'email':newEmail}) .then((data) => console.log(data)) .catch((err) => console.log(err)); } '''

profile picture
전문가
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인