mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 13:49:54 -06:00
* add new onboarding for new and existing Formbricks users * Add new personalized template view --------- Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
90 lines
2.2 KiB
TypeScript
90 lines
2.2 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,
|
|
onboardingDisplayed: 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}`);
|
|
}
|
|
};
|