fix: Do not try to parse an empty response
This commit is contained in:
@ -11,6 +11,7 @@ import {
|
|||||||
} from '../utils/publicUserProps';
|
} from '../utils/publicUserProps';
|
||||||
import { fixCompletedChallengeItem } from '../../common/utils';
|
import { fixCompletedChallengeItem } from '../../common/utils';
|
||||||
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
|
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
|
||||||
|
import { removeCookies } from '../utils/getSetAccessToken';
|
||||||
|
|
||||||
const log = debugFactory('fcc:boot:user');
|
const log = debugFactory('fcc:boot:user');
|
||||||
const sendNonUserToHome = ifNoUserRedirectTo(homeLocation);
|
const sendNonUserToHome = ifNoUserRedirectTo(homeLocation);
|
||||||
@ -187,21 +188,13 @@ function postResetProgress(req, res, next) {
|
|||||||
function createPostDeleteAccount(app) {
|
function createPostDeleteAccount(app) {
|
||||||
const { User } = app.models;
|
const { User } = app.models;
|
||||||
return function postDeleteAccount(req, res, next) {
|
return function postDeleteAccount(req, res, next) {
|
||||||
User.destroyById(req.user.id, function(err) {
|
return User.destroyById(req.user.id, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
req.logout();
|
req.logout();
|
||||||
req.flash('success', 'You have successfully deleted your account.');
|
removeCookies(req, res);
|
||||||
const config = {
|
return res.sendStatus(200);
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import { navigate } from 'gatsby';
|
|||||||
import { call, put, takeEvery } from 'redux-saga/effects';
|
import { call, put, takeEvery } from 'redux-saga/effects';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
deleteAccountComplete,
|
|
||||||
deleteAccountError,
|
deleteAccountError,
|
||||||
resetProgressComplete,
|
resetProgressComplete,
|
||||||
resetProgressError
|
resetProgressError
|
||||||
@ -13,12 +12,16 @@ import { createFlashMessage } from '../../components/Flash/redux';
|
|||||||
|
|
||||||
function* deleteAccountSaga() {
|
function* deleteAccountSaga() {
|
||||||
try {
|
try {
|
||||||
const { data: response } = yield call(postDeleteAccount);
|
yield call(postDeleteAccount);
|
||||||
yield put(deleteAccountComplete(response));
|
yield put(
|
||||||
|
createFlashMessage({
|
||||||
|
type: 'info',
|
||||||
|
message: 'Your account has been successfully deleted'
|
||||||
|
})
|
||||||
|
);
|
||||||
// remove current user information from application state
|
// remove current user information from application state
|
||||||
yield put(resetUserData());
|
yield put(resetUserData());
|
||||||
yield call(navigate, '/');
|
yield call(navigate, '/');
|
||||||
yield put(createFlashMessage(response));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yield put(deleteAccountError(e));
|
yield put(deleteAccountError(e));
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,6 @@ export const resetProgressComplete = createAction(types.resetProgressComplete);
|
|||||||
export const resetProgressError = createAction(types.resetProgressError);
|
export const resetProgressError = createAction(types.resetProgressError);
|
||||||
|
|
||||||
export const deleteAccount = createAction(types.deleteAccount);
|
export const deleteAccount = createAction(types.deleteAccount);
|
||||||
export const deleteAccountComplete = createAction(types.deleteAccountComplete);
|
|
||||||
export const deleteAccountError = createAction(types.deleteAccountError);
|
export const deleteAccountError = createAction(types.deleteAccountError);
|
||||||
|
|
||||||
export const usernameValidationSelector = state => state[ns].usernameValidation;
|
export const usernameValidationSelector = state => state[ns].usernameValidation;
|
||||||
|
Reference in New Issue
Block a user