[Feature] Implement Self-Serve Account Deletion

This commit is contained in:
Amruth Pillai
2023-01-19 00:11:15 +01:00
parent 5024c19f87
commit ff101dbfac
14 changed files with 235 additions and 14 deletions

View File

@ -2,7 +2,7 @@ import { User } from '@reactive-resume/schema';
import { AxiosResponse } from 'axios';
import toast from 'react-hot-toast';
import { setAccessToken, setUser } from '@/store/auth/authSlice';
import { logout, setAccessToken, setUser } from '@/store/auth/authSlice';
import store from '../store';
import axios from './axios';
@ -37,6 +37,10 @@ export type ResetPasswordParams = {
password: string;
};
export type UpdateProfileParams = {
name: string;
};
export const login = async (loginParams: LoginParams) => {
const {
data: { user, accessToken },
@ -75,3 +79,23 @@ export const resetPassword = async (resetPasswordParams: ResetPasswordParams) =>
toast.success('Your password has been changed successfully, please login again.');
};
export const updateProfile = async (updateProfileParams: UpdateProfileParams) => {
const { data: user } = await axios.patch<User, AxiosResponse<User>, UpdateProfileParams>(
'/auth/update-profile',
updateProfileParams
);
store.dispatch(setUser(user));
toast.success('Your profile has been successfully updated.');
};
export const deleteAccount = async () => {
await axios.delete('/resume/all');
await axios.delete('/auth');
store.dispatch(logout());
toast.success('Your account has been deleted, hope to see you again soon.');
};