Files
sign/packages/lib/server-only/user/create-user.ts

38 lines
861 B
TypeScript
Raw Normal View History

2023-06-09 18:21:18 +10:00
import { hash } from 'bcrypt';
import { prisma } from '@documenso/prisma';
import { IdentityProvider } from '@documenso/prisma/client';
import { SALT_ROUNDS } from '../../constants/auth';
export interface CreateUserOptions {
name: string;
email: string;
password: string;
2023-09-01 19:46:44 +10:00
signature?: string | null;
2023-06-09 18:21:18 +10:00
}
2023-09-01 19:46:44 +10:00
export const createUser = async ({ name, email, password, signature }: CreateUserOptions) => {
2023-06-09 18:21:18 +10:00
const hashedPassword = await hash(password, SALT_ROUNDS);
const userExists = await prisma.user.findFirst({
where: {
email: email.toLowerCase(),
},
});
if (userExists) {
throw new Error('User already exists');
}
return await prisma.user.create({
data: {
name,
email: email.toLowerCase(),
password: hashedPassword,
2023-09-01 19:46:44 +10:00
signature,
2023-06-09 18:21:18 +10:00
identityProvider: IdentityProvider.DOCUMENSO,
},
});
};