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

profile picture
专家
已提问 5 个月前46 查看次数
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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则