first commit

This commit is contained in:
2026-06-11 09:04:28 +03:30
commit e4dce4491c
27 changed files with 4422 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import prisma from '@/lib/prisma';
import bcrypt from 'bcrypt';
import { signToken } from '@/lib/auth';
export async function POST(req) {
try {
const { username, password } = await req.json();
if (!username || !password) {
return Response.json({ error: 'نام کاربری و رمز عبور الزامی است.' }, { status: 400 });
}
const user = await prisma.user.findUnique({
where: { username }
});
if (!user) {
return Response.json({ error: 'کاربر یافت نشد.' }, { status: 404 });
}
const isMatch = await bcrypt.compare(password, user.password);
if (!isMatch) {
return Response.json({ error: 'رمز عبور اشتباه است.' }, { status: 401 });
}
const token = signToken({ id: user.id, username: user.username, name: user.name, orgId: user.orgId, role: user.role });
return Response.json({ message: 'با موفقیت وارد شدید', token, user: { id: user.id, name: user.name, orgId: user.orgId, role: user.role } });
} catch (error) {
console.error(error);
return Response.json({ error: 'خطای سرور رخ داد.' }, { status: 500 });
}
}