mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-25 18:48:58 -06:00
* feat: add deletes account button on profile section. * feat: add delete account action when user click on delete account button * feat:logout user when his account is deleted * feat: added warning message before user deletes account * feat: add description to Delete account section * fix: fix: build issue. * fix: avoid giving the ownership of a team to a member who is not an admin * fix: merge conflict * fix: use !== in delete button disabled prop * fix: typo semething -> Something * refactor: simplified user deletion logic * refactor: explain user deletion logic * refactor: remove unecessary delete membership queries * feat: add deletes account button on profile section. * feat: add delete account action when user click on delete account button * feat:logout user when his account is deleted * feat: added warning message before user deletes account * fix merge conlicts * update to delete info text * feat: delete the team if the owner deletes his account and the team has no admins * add await
106 lines
2.6 KiB
TypeScript
106 lines
2.6 KiB
TypeScript
import { hashPassword } from "../auth";
|
|
|
|
export const createUser = async (
|
|
name: string,
|
|
email: string,
|
|
password: string,
|
|
inviteToken?: string | null
|
|
): Promise<any> => {
|
|
const hashedPassword = await hashPassword(password);
|
|
try {
|
|
const res = await fetch(`/api/v1/users`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
name,
|
|
email,
|
|
password: hashedPassword,
|
|
inviteToken,
|
|
onboardingCompleted: false,
|
|
}),
|
|
});
|
|
if (res.status !== 200) {
|
|
const json = await res.json();
|
|
throw Error(json.error);
|
|
}
|
|
return await res.json();
|
|
} catch (error: any) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const resendVerificationEmail = async (email: string): Promise<any> => {
|
|
try {
|
|
const res = await fetch(`/api/v1/users/verification-email`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
email,
|
|
}),
|
|
});
|
|
if (res.status !== 200) {
|
|
const json = await res.json();
|
|
throw Error(json.error);
|
|
}
|
|
return await res.json();
|
|
} catch (error: any) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const forgotPassword = async (email: string) => {
|
|
try {
|
|
const res = await fetch(`/api/v1/users/forgot-password`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
email,
|
|
}),
|
|
});
|
|
if (res.status !== 200) {
|
|
const json = await res.json();
|
|
throw Error(json.error);
|
|
}
|
|
return await res.json();
|
|
} catch (error: any) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const resetPassword = async (token: string, password: string): Promise<any> => {
|
|
const hashedPassword = await hashPassword(password);
|
|
try {
|
|
const res = await fetch(`/api/v1/users/reset-password`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
token,
|
|
hashedPassword,
|
|
}),
|
|
});
|
|
if (res.status !== 200) {
|
|
const json = await res.json();
|
|
throw Error(json.error);
|
|
}
|
|
return await res.json();
|
|
} catch (error: any) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const deleteProfile = async (): Promise<any> => {
|
|
try {
|
|
const res = await fetch("/api/v1/users/me/", {
|
|
method: "DELETE",
|
|
headers: { "Content-Type": "application/json" },
|
|
});
|
|
if (res.status !== 200) {
|
|
const json = await res.json();
|
|
throw Error(json.error);
|
|
}
|
|
return await res.json();
|
|
} catch (error) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|