MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / create

Function create

apps/web/pages/api/reset-password/index.ts:6–34  ·  view source on GitHub ↗
(request: NextApiRequest, response: NextApiResponse)

Source from the content-addressed store, hash-verified

4import { cors, preflight } from 'utilities/cors';
5
6async function create(request: NextApiRequest, response: NextApiResponse) {
7 const { password, token }: { password?: string; token?: string } = JSON.parse(
8 request.body
9 );
10 if (!password) {
11 return response.status(400).json({ error: 'Password is required' });
12 }
13 if (!token) {
14 return response.status(400).json({ error: 'Token is required' });
15 }
16 const auth = await prisma.auths.findFirst({ where: { token } });
17 if (!auth) {
18 return response.status(200).json({});
19 }
20 const hash = generateHash(password, auth.salt);
21 try {
22 await prisma.auths.update({
23 where: { id: auth.id },
24 data: {
25 password: hash,
26 token: null,
27 },
28 });
29 } catch (exception) {
30 console.error(exception);
31 response.status(200).json({});
32 }
33 return response.status(200).json({});
34}
35
36async function handler(request: NextApiRequest, response: NextApiResponse) {
37 if (request.method === 'OPTIONS') {

Callers 1

handlerFunction · 0.70

Calls 3

generateHashFunction · 0.90
errorMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected