Skip to content

Issues with recoverAccount #42

@markfazzio

Description

@markfazzio

When trying to implement recoverAccount(), I keep getting the "user not found" error. I did not see many docs on this. The error:

code: 404
msg: "User not found"
  • I am able to send the reset password email successfully
  • I am able to get the token from useIdentityContext() and show my <RecoverAccountModal /> successfully
  • Then I call recoverAccount() with the updated password and get a successful user response, which I use to set updated user inside setUser(recoveredUser)

However, it fails when I call updateUser(). When I console.log the user from useIdentityContext() it is undefined, so I know that setUser() is not working properly for me, perhaps not finishing before updateUser() is called. But, it is not a promise, so await will not help. Any assistance would be hugely appreciated. Here is my code:

RecoverAccountModal.tsx

        // ensure passwords match and not empty
         if (password !== '' && password === confirmPassword) {
              // recover account using token from reset password email
              await recoverAccount(true)
                .then(async user => {
                  // log in the current user so we can call updateUser
                  setUser(user);
                  await updateUser({ password })
                    .then(updatedUser => {
                      setMessage('Password updated successfully!');
                    })
                    .catch(error => {
                      console.log('Failed to update user:', error);
                      setMessage(
                        'Password cannot be updated. Please try getting a new recovery link.'
                      );
                    });
                })
                .catch(err => {
                  console.log('Error running recoverAccount()', err);
                });
            } else {
              setMessage('Passwords do not match.');
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions