Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
User object is getting populated but Auth.currentSession is returning "No user found"

When the user clicks on the "sign-in" button and if user.challangeName === 'NEW_PASSWORD_REQUIRED'is true, I redirect the user to a page (form screen) where he can provide the input for required attributes and a new password. Even tho the user object is getting populated upon clicking on the sign-in button, using Auth.currentsession on the form screen will print "No user found"

Can someone let me know why I'm seeing no user? What am I doing wrong here?

Here's my login function (triggered when clicked on sign-in button) where I direct the user to the change password screen (form screen) if user.challangeName === 'NEW_PASSWORD_REQUIRED' is true.

const login = async (email, password) => {
    try {
        const user = await Auth.signIn(email, password);

        if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
            navigate('/change-password');
            return;
        }

        if (user) {
            setToken(user.signInUserSession.idToken.jwtToken);

            const userDetails = await getAccountDetails();

            dispatch({
                type: LOGIN,
                payload: {
                    user: {
                        attributes: user.attributes,
                        username: user.username
                    },
                    client: userDetails
                }
            });
        }
    } catch (error) {
        await logout();

        throw error;
    }
};

Here's my onSubmit function on the change password screen where eventually I want to use Auth.completeNewPassword to update the user's password in Cognito

 const onSubmitClick = (e) => {
        e.preventDefault();

        if (validateFields());

        Auth.currentSession()
            .then((user) => console.log(user))
            .catch((err) => console.log(err));

    };

Here's the documentation provided by AWS https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/#forgot-password, and the code provided by AWS to update password

Auth.signIn(username, password)
.then(user => {
    if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
        const { requiredAttributes } = user.challengeParam; // the array of required attributes, e.g ['email', 'phone_number']
        Auth.completeNewPassword(
            user,               // the Cognito User Object
            newPassword,       // the new password
            // OPTIONAL, the required attributes
            {
              email: 'xxxx@example.com',
              phone_number: '1234567890'
            }
        ).then(user => {
            // at this time the user is logged in if no MFA required
            console.log(user);
        }).catch(e => {
          console.log(e);
        });
    } else {
        // other situations
    }
}).catch(e => {
    console.log(e);
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

New updated answer to reflect your updated post, change the onSubmitClick to the following:

const onSubmitClick = (e) => {
    e.preventDefault();

    if (validateFields());

    Auth.currentAuthenticatedUser()
        .then(user => {
            console.log(user))
        })
        .then((data) => console.log(data))
        .catch((err) => console.log(err));
};

You are looking at the documentation which shows how to use the user after Auth.signIn() (which was my previous answer), compared to what you use: Auth.currentAuthenticatedUser(). The proper documentation example you have to look at is this one: https://www.docs.amplify.aws/lib/auth/manageusers/q/platform/js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!