changePassword.js 913 B

123456789101112131415161718192021222324252627282930
  1. import { put, call } from 'redux-saga/effects';
  2. import axios from 'axios';
  3. import { USER_URL } from './../../constants/user';
  4. import { changePasswordSuccess, changePasswordFailure } from './../../actions/user/changePassword';
  5. import storageKey from '../../utils/storageKey';
  6. const getItem = localStorage.getItem(storageKey);
  7. export default function* ({payload:{_id, password, confirmPassword}}) {
  8. try {
  9. const config = {
  10. headers: {
  11. "Content-Type": "application/json",
  12. "Authorization": `Bearer ${getItem}`
  13. }
  14. }
  15. const user = yield call(() =>
  16. axios.put(`${USER_URL}${_id}`,{
  17. password, confirmPassword}, config)
  18. .then(({ data }) => data)
  19. )
  20. yield put(changePasswordSuccess(user));
  21. }
  22. catch ({ message }) {
  23. yield put(changePasswordFailure(message));
  24. }
  25. }