fix: Do not try to parse an empty response
This commit is contained in:
@ -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);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user