Files
formbricks/lib/users.ts
Matthias Nannt 0aa931287f Feature/add signup (#5)
* update prisma model to support user

* add signup page

* add email verification

* remove seed user

* update README and Dockerfile to support signup and the removal of seed data
2022-07-14 01:04:02 +09:00

44 lines
1.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/verfication-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}`);
}
};