(request: NextApiRequest, response: NextApiResponse)
| 4 | import { cors, preflight } from 'utilities/cors'; |
| 5 | |
| 6 | async 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 | |
| 36 | async function handler(request: NextApiRequest, response: NextApiResponse) { |
| 37 | if (request.method === 'OPTIONS') { |
no test coverage detected