Skip to content
Snippets Groups Projects
Commit 0a542b3e authored by adietmue's avatar adietmue Committed by Johannes Zumthurm
Browse files

Update file actions.js

parent 56cef640
Branches how_to_ersti_24
No related tags found
1 merge request!145User password fix
......@@ -65,24 +65,33 @@ const changePassword =
dispatch({ type: USER_PENDING, action: USER_ACTION_PASSWORD })
// The API only allows to change the password with a fresh session,
// so we create a temporary new session.
// so we create a temporary new session. This changes the user eTag,
// so we need to re-fetch it.
return axios
.post(`${apiUrl}/sessions`, {
username: user.nethz || user._id,
password: currentPassword,
})
.then(response => {
const session = response.data
return dispatch({
types: [null, USER_SUCCESS, USER_ERROR],
resource: 'users',
itemId: user._id,
etag: user._etag,
method: 'PATCH',
data: { password: newPassword || null },
token: session.token,
})
const token = response.data.token
// Fetch updated etag and then update password.
return axios
.get(`${apiUrl}/users/${user._id}`)
.then(user_response => {
const etag = user_response.data._etag
return dispatch({
types: [null, USER_SUCCESS, USER_ERROR],
resource: 'users',
itemId: user._id,
etag: etag,
method: 'PATCH',
data: { password: newPassword || null },
token: token,
})
})
.catch(error => {
return dispatch({ type: USER_ERROR, error })
})
})
.catch(error => {
return dispatch({ type: USER_ERROR, error })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment