diff --git a/api-server/server/boot/user.js b/api-server/server/boot/user.js index c768511607..eab8259264 100644 --- a/api-server/server/boot/user.js +++ b/api-server/server/boot/user.js @@ -11,6 +11,7 @@ import { } from '../utils/publicUserProps'; import { fixCompletedChallengeItem } from '../../common/utils'; import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware'; +import { removeCookies } from '../utils/getSetAccessToken'; const log = debugFactory('fcc:boot:user'); const sendNonUserToHome = ifNoUserRedirectTo(homeLocation); @@ -187,21 +188,13 @@ function postResetProgress(req, res, next) { function createPostDeleteAccount(app) { const { User } = app.models; return function postDeleteAccount(req, res, next) { - User.destroyById(req.user.id, function(err) { + return User.destroyById(req.user.id, function(err) { if (err) { return next(err); } req.logout(); - req.flash('success', 'You have successfully deleted your account.'); - const config = { - signed: !!req.signedCookies, - domain: process.env.COOKIE_DOMAIN || 'localhost' - }; - res.clearCookie('jwt_access_token', config); - res.clearCookie('access_token', config); - res.clearCookie('userId', config); - res.clearCookie('_csrf', config); - return res.status(200).end(); + removeCookies(req, res); + return res.sendStatus(200); }); }; } diff --git a/client/src/redux/settings/danger-zone-saga.js b/client/src/redux/settings/danger-zone-saga.js index 52a0f941dc..fc7482f2bf 100644 --- a/client/src/redux/settings/danger-zone-saga.js +++ b/client/src/redux/settings/danger-zone-saga.js @@ -2,7 +2,6 @@ import { navigate } from 'gatsby'; import { call, put, takeEvery } from 'redux-saga/effects'; import { - deleteAccountComplete, deleteAccountError, resetProgressComplete, resetProgressError @@ -13,12 +12,16 @@ import { createFlashMessage } from '../../components/Flash/redux'; function* deleteAccountSaga() { try { - const { data: response } = yield call(postDeleteAccount); - yield put(deleteAccountComplete(response)); + yield call(postDeleteAccount); + yield put( + createFlashMessage({ + type: 'info', + message: 'Your account has been successfully deleted' + }) + ); // remove current user information from application state yield put(resetUserData()); yield call(navigate, '/'); - yield put(createFlashMessage(response)); } catch (e) { yield put(deleteAccountError(e)); } diff --git a/client/src/redux/settings/index.js b/client/src/redux/settings/index.js index 6abe451926..ed3f18a566 100644 --- a/client/src/redux/settings/index.js +++ b/client/src/redux/settings/index.js @@ -97,7 +97,6 @@ export const resetProgressComplete = createAction(types.resetProgressComplete); export const resetProgressError = createAction(types.resetProgressError); export const deleteAccount = createAction(types.deleteAccount); -export const deleteAccountComplete = createAction(types.deleteAccountComplete); export const deleteAccountError = createAction(types.deleteAccountError); export const usernameValidationSelector = state => state[ns].usernameValidation;