Update src/app/api/auth/login/route.ts
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { compare } from 'bcryptjs';
|
||||
|
||||
// Temporary in-memory user storage (replace with database)
|
||||
const users: Map<string, any> = new Map();
|
||||
@@ -25,8 +24,9 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
// Compare password
|
||||
const isPasswordValid = await compare(password, user.password);
|
||||
// Compare password using simple hash (not production-ready)
|
||||
const hashedPassword = await hashPassword(password);
|
||||
const isPasswordValid = hashedPassword === user.password;
|
||||
if (!isPasswordValid) {
|
||||
return NextResponse.json(
|
||||
{ message: 'Invalid email or password' },
|
||||
@@ -56,3 +56,12 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Simple hash function (not secure - for development only)
|
||||
async function hashPassword(password: string): Promise<string> {
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(password);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user