Files
opengifame/pages/api/user/create.ts
Fergal Moran d131663c36 Sort terms
2022-10-15 17:14:34 +01:00

29 lines
757 B
TypeScript

import type { NextApiRequest, NextApiResponse } from 'next';
import prisma from '@lib/prismadb';
import { logger } from '@lib/logger';
import { hashPassword } from '@lib/crypt';
import { omit } from 'lodash';
export default async function handle(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === 'POST') {
logger.debug('creating user', {
...req.body,
password: hashPassword(req.body.password),
});
const user = await prisma.user.create({
data: {
email: req.body.email,
password: await hashPassword(req.body.password),
},
});
res.json(omit(user, 'password'));
} else {
throw new Error(
`The HTTP ${req.method} method is not supported at this route.`
);
}
}