Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Fixed crash when deleting user account

Blue Mouseb19840adf44f
diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsx
index dc295d346..4b793a1f4 100644
--- a/src/pages/UserSettings/UserSettings.container.jsx
+++ b/src/pages/UserSettings/UserSettings.container.jsx
@@ -1,4 +1,5 @@
-import React from 'react'
+import React, { memo } from 'react'
+import { useHistory } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
@@ -7,25 +8,28 @@ import _isNull from 'lodash/isNull'
import {
CONFIRMATION_TIMEOUT, GDPR_REQUEST, GDPR_EXPORT_TIMEFRAME,
} from 'redux/constants'
+import { isAuthenticated } from 'hoc/protected'
import { authActions } from 'redux/actions/auth'
import { errorsActions } from 'redux/actions/errors'
import { alertsActions } from 'redux/actions/alerts'
import { getCookie, setCookie } from 'utils/cookie'
import { confirmEmail, exportUserData } from 'api'
-
+import routes from 'routes'
import UserSettings from './UserSettings'
dayjs.extend(utc)
const UserSettingsContainer = () => {
const dispatch = useDispatch()
+ const history = useHistory()
const onDelete = () => {
dispatch(
authActions.deleteAccountAsync(
(error) => dispatch(
errorsActions.deleteAccountFailed(error.description),
- )
+ ),
+ () => history.push(routes.main),
)
)
}
@@ -93,4 +97,4 @@ const UserSettingsContainer = () => {
)
}
-export default UserSettingsContainer
+export default isAuthenticated(memo(UserSettingsContainer))
diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsx
index 6ce828c5d..8631168bc 100644
--- a/src/pages/UserSettings/UserSettings.jsx
+++ b/src/pages/UserSettings/UserSettings.jsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect, memo } from 'react'
+import React, { useState, useEffect } from 'react'
import { useSelector } from 'react-redux'
import _size from 'lodash/size'
import _isEmpty from 'lodash/isEmpty'
@@ -11,7 +11,6 @@ import Button from 'ui/Button'
import Modal from 'ui/Modal'
import Select from 'ui/Select'
import { isValidEmail, isValidPassword } from 'utils/validator'
-import { isAuthenticated } from 'hoc/protected'
const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
const { user } = useSelector(state => state.auth)
@@ -212,4 +211,4 @@ const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
)
}
-export default isAuthenticated(memo(UserSettings))
+export default UserSettings
diff --git a/src/redux/actions/auth/index.js b/src/redux/actions/auth/index.js
index ab58f0774..734e41204 100644
--- a/src/redux/actions/auth/index.js
+++ b/src/redux/actions/auth/index.js
@@ -100,10 +100,10 @@ export const authActions = {
}
},
- deleteAccountAsync(errorCallback) {
+ deleteAccountAsync(errorCallback, successCallback) {
return {
type: types.DELETE_ACCOUNT_ASYNC,
- payload: { errorCallback }
+ payload: { errorCallback, successCallback },
}
}
}
diff --git a/src/redux/sagas/auth/workers/deleteUserAccount.js b/src/redux/sagas/auth/workers/deleteUserAccount.js
index 0c4b55b0c..ecd024836 100644
--- a/src/redux/sagas/auth/workers/deleteUserAccount.js
+++ b/src/redux/sagas/auth/workers/deleteUserAccount.js
@@ -4,10 +4,11 @@ import { authActions } from 'redux/actions/auth'
import { alertsActions } from 'redux/actions/alerts'
import { deleteUser } from 'api'
-export default function* deleteUserAccountWorker({ payload: { errorCallback } }) {
+export default function* deleteUserAccountWorker({ payload: { errorCallback, successCallback } }) {
try {
yield call(deleteUser)
yield put(authActions.deleteAccountSuccess())
+ yield call(successCallback)
yield put(alertsActions.accountDeleted('Your account has been deleted'))
} catch (e) {
errorCallback(JSON.parse(e.message))