Has anyone successfully used the /auth/change-password api?

System Information
  • Strapi Version: 4.4.1
  • Operating System: Windows (development system)
  • Database: MySQL
  • Node Version: N/A
  • NPM Version: N/A
  • Yarn Version: N/A

Has anyone been able to successfully use this api to change a password? When I try it, I get a URL 400 - Bad request. I’m using plain Javascript and the current version (4.4.1) of Strapi.

Thanks all…


These days I use passwordless and Google auth. Implementing the password reset follows means

  1. Extra screens on the frontend
  2. Storing passwords
  3. Email templates

It would be easier to diagnose the problem if you post screenshots of the response message you have been getting

I’m trying to do it this way because it’s part of the spec. I could probably get it changed but I’d like to know why this doesn’t work. This is my code:

async function changePassword() {

fetchURL = ${dbPath}api/auth/change-password;

fetchHeader = new Headers();

fetchHeader.append(“Authorization”, Bearer ${jwtString});

fetchHeader.append(“Content-Type”, “application/json”);

fetchCommand = new Request(fetchURL, {

method: "POST",

headers: fetchHeader,

body: JSON.stringify({

    currentPassword: oldPasswordInput.value,

    password: newPasswordInput.value,

    passwordConfirmation: confirmPasswordInput.value

  })

})

try {

response = await fetch(fetchCommand);

if (response.ok) {

  data = await response.json();

  modalText.innerText = "Password successfully changed";

  displayModalContainer();

} else {

  modalText.innerText = "Password not changed";

  displayModalContainer();

}

} catch (err) {

console.log("User Fetch error", err);

}

And this is the response I’m getting:

POST http://localhost:1337/api/auth/change-password 400 (Bad Request)

It would have helped if I had formatted the body correctly - it should be:

body: JSON.stringify({
    "currentPassword": oldPasswordInput.value,
    "password": newPasswordInput.value,
    "passwordConfirmation": confirmPasswordInput.value
  })

currentPassword, password & passwordConfirmation have to be in quotes, sigh…

1 Like