diff options
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/sagas/index.js | 4 | ||||
| -rw-r--r-- | src/api/sagas/profile.js | 12 | ||||
| -rw-r--r-- | src/api/sagas/users.js | 2 |
3 files changed, 17 insertions, 1 deletions
diff --git a/src/api/sagas/index.js b/src/api/sagas/index.js index 426b344a..7fe57453 100644 --- a/src/api/sagas/index.js +++ b/src/api/sagas/index.js @@ -1,7 +1,8 @@ import {takeEvery} from "redux-saga/effects"; import {LOG_IN} from "../../actions/auth"; import {ADD_SIMULATION, DELETE_SIMULATION} from "../../actions/simulations"; -import {FETCH_AUTHORIZATIONS_OF_CURRENT_USER} from "../../actions/users"; +import {DELETE_CURRENT_USER, FETCH_AUTHORIZATIONS_OF_CURRENT_USER} from "../../actions/users"; +import {onDeleteCurrentUser} from "./profile"; import {onSimulationAdd, onSimulationDelete} from "./simulations"; import {onFetchAuthorizationsOfCurrentUser, onFetchLoggedInUser} from "./users"; @@ -10,4 +11,5 @@ export default function* rootSaga() { yield takeEvery(FETCH_AUTHORIZATIONS_OF_CURRENT_USER, onFetchAuthorizationsOfCurrentUser); yield takeEvery(ADD_SIMULATION, onSimulationAdd); yield takeEvery(DELETE_SIMULATION, onSimulationDelete); + yield takeEvery(DELETE_CURRENT_USER, onDeleteCurrentUser); } diff --git a/src/api/sagas/profile.js b/src/api/sagas/profile.js new file mode 100644 index 00000000..3c4e1825 --- /dev/null +++ b/src/api/sagas/profile.js @@ -0,0 +1,12 @@ +import {call, put} from "redux-saga/effects"; +import {deleteCurrentUserSucceeded} from "../../actions/users"; +import {deleteUser} from "../routes/users"; + +export function* onDeleteCurrentUser(action) { + try { + yield call(deleteUser, action.userId); + yield put(deleteCurrentUserSucceeded()); + } catch (error) { + console.log(error); + } +} diff --git a/src/api/sagas/users.js b/src/api/sagas/users.js index d3ef32a6..c1daab30 100644 --- a/src/api/sagas/users.js +++ b/src/api/sagas/users.js @@ -2,6 +2,7 @@ import {call, put} from "redux-saga/effects"; import {logInSucceeded} from "../../actions/auth"; import {addToAuthorizationStore} from "../../actions/objects"; import {fetchAuthorizationsOfCurrentUserSucceeded} from "../../actions/users"; +import {saveAuthLocalStorage} from "../../auth/index"; import {performTokenSignIn} from "../routes/auth"; import {addUser, getAuthorizationsByUser} from "../routes/users"; import {fetchAndStoreSimulation, fetchAndStoreUser} from "./objects"; @@ -12,6 +13,7 @@ export function* onFetchLoggedInUser(action) { let userId = tokenResponse.userId; if (tokenResponse.isNewUser) { + saveAuthLocalStorage({authToken: action.payload.authToken}); const newUser = yield call(addUser, action.payload); userId = newUser.id; } |
