Skip to content
Snippets Groups Projects
route.ts 704 B
Newer Older
Yusuf Akgül's avatar
Yusuf Akgül committed
import { db } from '@/lib/db'
Yusuf Akgül's avatar
Yusuf Akgül committed
import { hash } from 'bcrypt'
import { NextResponse } from 'next/server'

export async function POST(req: Request) {
    try {
Yusuf Akgül's avatar
Yusuf Akgül committed
        const { username, email, password } = await req.json()
Yusuf Akgül's avatar
Yusuf Akgül committed
        const hashed = await hash(password, 12)

Yusuf Akgül's avatar
Yusuf Akgül committed
        const user = await db.user.create({
Yusuf Akgül's avatar
Yusuf Akgül committed
            data: {
Yusuf Akgül's avatar
Yusuf Akgül committed
                username,
Yusuf Akgül's avatar
Yusuf Akgül committed
                email,
                password: hashed
            }
        })

        return NextResponse.json({
Yusuf Akgül's avatar
Yusuf Akgül committed
            username: user.username,
            email: user.email
Yusuf Akgül's avatar
Yusuf Akgül committed
        })
    } catch (err: any) {
Yusuf Akgül's avatar
Yusuf Akgül committed
        return new NextResponse(JSON.stringify({
            error: err.message
        }), { status: 500 }
Yusuf Akgül's avatar
Yusuf Akgül committed
        )
    }
}