mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-09 08:09:46 -06:00
Move repository into a monorepo with turborepo and pnpm. This is a big change in the way the code is organized, used and deployed.
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { hashPassword } from "./auth";
|
|
|
|
export const createUser = async (firstname, lastname, email, password) => {
|
|
const hashedPassword = await hashPassword(password);
|
|
try {
|
|
const res = await fetch(`/api/public/users`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
firstname,
|
|
lastname,
|
|
email,
|
|
password: hashedPassword,
|
|
}),
|
|
});
|
|
if (res.status !== 200) {
|
|
const json = await res.json();
|
|
throw Error(json.error);
|
|
}
|
|
return await res.json();
|
|
} catch (error) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const resendVerificationEmail = async (email) => {
|
|
try {
|
|
const res = await fetch(`/api/public/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) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const forgotPassword = async (email: string) => {
|
|
try {
|
|
const res = await fetch(`/api/public/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) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const resetPassword = async (token, password) => {
|
|
const hashedPassword = await hashPassword(password);
|
|
try {
|
|
const res = await fetch(`/api/public/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) {
|
|
throw Error(`${error.message}`);
|
|
}
|
|
};
|