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 Antwort
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
EXPERTE
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen