mirror of
https://github.com/fergalmoran/opengifame.git
synced 2025-12-25 11:09:40 +00:00
29 lines
757 B
TypeScript
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.`
|
|
);
|
|
}
|
|
}
|