first commit

This commit is contained in:
2026-01-17 14:17:42 +05:30
commit 0f194eb9e7
328 changed files with 73544 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import { handlers } from '@/auth'
export const { GET, POST } = handlers

View File

@@ -0,0 +1,72 @@
import { NextRequest, NextResponse } from "next/server";
import { hash } from 'bcryptjs'
import { prisma } from '@/lib/prisma'
import { signUpSchema } from '@/lib/validations/auth'
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { name, email, password, phone, referralCode, role } = signUpSchema.parse(body)
// Check if user already exists
const existingUser = await prisma.user.findUnique({
where: { email },
})
if (existingUser) {
return NextResponse.json(
{ error: 'User already exists' },
{ status: 400 }
)
}
// Hash password
const hashedPassword = await hash(password, 12)
// Find referrer if referral code is provided
let referrerId = null
if (referralCode) {
const referrer = await prisma.user.findUnique({
where: { referralCode },
})
if (referrer) {
referrerId = referrer.id
}
}
// Create user
const user = await prisma.user.create({
data: {
name,
email,
password: hashedPassword,
phone,
role: role || 'CUSTOMER',
referrerId,
},
})
// Create wallet for members
if (role === 'MEMBER') {
await prisma.wallet.create({
data: {
userId: user.id,
balance: 0,
totalEarnings: 0,
totalWithdrawn: 0,
},
})
}
return NextResponse.json(
{ message: 'User created successfully', userId: user.id },
{ status: 201 }
)
} catch (error) {
console.error('Signup error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}