Client - add account deletion
This commit is contained in:
@ -12,7 +12,11 @@ import {
|
||||
} from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUserActions, IUserState } from '@/store/modules/user/types'
|
||||
import { ILoginOrRegisterData, IUserPayload } from '@/types/user'
|
||||
import {
|
||||
ILoginOrRegisterData,
|
||||
IUserDeletionPayload,
|
||||
IUserPayload,
|
||||
} from '@/types/user'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
@ -104,4 +108,22 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USER_STORE.ACTIONS.DELETE_ACCOUNT](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.delete(`users/${payload.username}`)
|
||||
.then((res) => {
|
||||
if (res.status === 204) {
|
||||
context
|
||||
.dispatch(USER_STORE.ACTIONS.LOGOUT)
|
||||
.then(() => router.push('/'))
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
export enum UserActions {
|
||||
CHECK_AUTH_USER = 'CHECK_AUTH_USER',
|
||||
DELETE_ACCOUNT = 'DELETE_ACCOUNT',
|
||||
GET_USER_PROFILE = 'GET_USER_PROFILE',
|
||||
LOGIN_OR_REGISTER = 'LOGIN_OR_REGISTER',
|
||||
LOGOUT = 'LOGOUT',
|
||||
|
@ -10,6 +10,7 @@ import { IRootState } from '@/store/modules/root/types'
|
||||
import {
|
||||
IAuthUserProfile,
|
||||
ILoginOrRegisterData,
|
||||
IUserDeletionPayload,
|
||||
IUserPayload,
|
||||
} from '@/types/user'
|
||||
|
||||
@ -41,6 +42,11 @@ export interface IUserActions {
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.DELETE_ACCOUNT](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IUserGetters {
|
||||
|
Reference in New Issue
Block a user