import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); import crypto from 'crypto'; import { promisify } from 'util'; export async function post({ cookies, request, redirect }) { if (request.headers.get('Content-Type') === 'application/json') { const body = await request.json(); const row = await prisma.user.findFirst({ where: { username: body.username, }, }); const scrypt = promisify(crypto.scrypt); async function verify(password, hash) { const hashBuffer = Buffer.from(hash, 'hex'); const derivedKey = await scrypt(password, row.salt, 64); return crypto.timingSafeEqual(hashBuffer, derivedKey); } const isSame = await verify(body.password, row.hash); if (isSame === true) { return redirect('https://twitch.tv'); } else { return redirect('https://youtube.com'); } } }