- Issue created by @grasmash
I'm not sure what the value of the provided `/user/{user}/password/update` endpoint is. Perhaps when it was written, JSON:API in Drupal core did not provide a way to update passwords. It does today:
/**
* Function to update a user's password
* @param {string} baseUrl - The base URL of the Drupal API
* @param {string} accessToken - The user's access token
* @param {string} refreshToken - The user's refresh token
* @param {string} userUuid - The UUID of the user
* @param {string} currentPassword - The current password
* @param {string} newPassword - The new password
* @returns {Promise} - Promise that resolves to the API response
*/
async function updateUserPassword(baseUrl, accessToken, refreshToken, userUuid, currentPassword, newPassword) {
// Request body with password change
const requestBody = {
data: {
type: 'user--user',
id: userUuid,
attributes: {
pass: {
existing: currentPassword,
value: newPassword
}
}
}
};
// Make the PATCH request
const response = await fetch(`${baseUrl}/jsonapi/user/user/${userUuid}`, {
method: 'PATCH',
headers: {
'Accept': 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json',
'Authorization': `Bearer ${accessToken}`
},
body: JSON.stringify(requestBody)
});
// Parse and return the response
return await response.json();
}
Example usage:
updateUserPassword(
'https://api.example.com',
'your-access-token',
'your-refresh-token',
'user-uuid',
'current-password',
'new-password'
).then(response => console.log(response));
Remove the endpoint.
Active
1.0
Code