how to change logged-in user password


I’ve created a password change menu for logged-in user in my JS app.
As usual user experience for this case I have to get old password and compare it with the logged-in user password, if it matches then update the user with new password .
but when I checked the password field of current user I found it’s undefined.
how can I update the logged in user password?
there is one solution in my mind which I’ll try:

  • since the password of current user is undefined . I can not compare it with old password field entry in my app
    so I will re login with current username and old password field value, if it logins successfully it means old password field and current user password is same so I will update the user with new password . If it does not login I will report an mismatch error message.
    what is a standard solution for this scenario.

I’ve tested with the above mentioned method which changed password perfectly

The approach you described sounds reasonable.