Amplify Javascript Client for Auth is not able to access auth session

0

I am using the code from the aws examples https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/#retrieve-current-authenticated-user and after signing up, signing in, I am trying to update the email. once I call the change email address, I am always getting an error:

Uncaught (in promise) TypeError: user.getSession is not a function which seems to come deep within the aws amplify auth module. Trying to find out what is wrong? If you follow the code below this is the order in which it is used.

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 Respuesta
1
Respuesta aceptada

Found this which solved the problem: https://github.com/aws-amplify/amplify-js/issues/10108

and also updated the changeEmail() to:

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

respondido hace un año
profile picture
EXPERTO
revisado hace 14 días
profile picture
EXPERTO
revisado hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas