diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index 007622d80..412ea0d82 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -19,6 +19,10 @@ export const CHANGE_EMAIL_REQUEST = 'CHANGE_EMAIL_REQUEST'; export const CHANGE_EMAIL_SUCCESS = 'CHANGE_EMAIL_SUCCESS'; export const CHANGE_EMAIL_FAIL = 'CHANGE_EMAIL_FAIL'; +export const DEACTIVATE_ACCOUNT_REQUEST = 'DEACTIVATE_ACCOUNT_REQUEST'; +export const DEACTIVATE_ACCOUNT_SUCCESS = 'DEACTIVATE_ACCOUNT_SUCCESS'; +export const DEACTIVATE_ACCOUNT_FAIL = 'DEACTIVATE_ACCOUNT_FAIL'; + export const CHANGE_PASSWORD_REQUEST = 'CHANGE_PASSWORD_REQUEST'; export const CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS'; export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL'; @@ -183,6 +187,23 @@ export function changeEmail(email, password) { }; } +export function deactivateAccount(password) { + return (dispatch, getState) => { + dispatch({ type: DEACTIVATE_ACCOUNT_REQUEST }); + return api(getState).post('/api/pleroma/disable_account', { + password, + }).then(response => { + if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure + dispatch({ type: DEACTIVATE_ACCOUNT_SUCCESS, response }); + dispatch({ type: AUTH_LOGGED_OUT }); + dispatch(showAlert('Successfully logged out.', '')); + }).catch(error => { + dispatch({ type: DEACTIVATE_ACCOUNT_FAIL, error, skipAlert: true }); + throw error; + }); + }; +} + export function changePassword(oldPassword, newPassword, confirmation) { return (dispatch, getState) => { dispatch({ type: CHANGE_PASSWORD_REQUEST }); diff --git a/app/soapbox/features/security/index.js b/app/soapbox/features/security/index.js index dd291a095..df8e75f4e 100644 --- a/app/soapbox/features/security/index.js +++ b/app/soapbox/features/security/index.js @@ -16,6 +16,7 @@ import { changePassword, fetchOAuthTokens, revokeOAuthToken, + deactivateAccount, } from 'soapbox/actions/auth'; import { showAlert } from 'soapbox/actions/alerts';