Next.js Discord

Discord Forum

405 error code after send POST data.

Answered
Buff-breasted Sandpiper posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by Buff-breasted Sandpiper
@Northeast Congo Lion my miss error is 500 rn.
But im idiot...

Im correct my errors and do one command xD npx prisma db pull
After using this command all working xD 🙂
View full answer

11 Replies

Buff-breasted Sandpiper
/app/api/createUser/route.js - api end-point for create a user

import { NextRequest, NextResponse } from "next/server";
import {PrismaClient} from '@prisma/client';
import bcrypt from 'bcrypt';


const prisma = new PrismaClient;

export async function POST(request) {

    if (request.method !== 'POST') {
        return new NextResponse(null, { status: 405 });
    }

    try {
        const data = await request.json();
        const { email, password, name, surname, avatarUrl } = data;

        const hashedPassword = await bcrypt.hash(password, 10);
        const newUser = await prisma.user.create({
            data: {
                email,
                password: hashedPassword,
                name,
                surname,
                avatarUrl
            }
        });

        return new NextResponse(JSON.stringify(newUser), {
            status: 201,
            headers: {
                'Content-Type': 'application/json'
            }
        });
    } catch (error) {
        console.error("Error creating user:", error);
        return new NextResponse(JSON.stringify({ error: 'Internal server error' }), {
            status: 500,
            headers: {
                'Content-Type': 'application/json'
            }
        });
    }
}
Here continue a code bcs limt = 760 🙂
Northeast Congo Lion
HTTP 405 is method not accepted
Eg post to a GET
Buff-breasted Sandpiper
@Northeast Congo Lion my miss error is 500 rn.
But im idiot...

Im correct my errors and do one command xD npx prisma db pull
After using this command all working xD 🙂
Answer
Buff-breasted Sandpiper
Before i do only prisma migrate and create user but not for appAdmin model in schema.prisma.
Northeast Congo Lion
so all sorted?
Buff-breasted Sandpiper
Yas!
But i have some questions u have time rn?
okay np.
@Buff-breasted Sandpiper okay np.
Northeast Congo Lion
just create another thread if u got any more questionss 🙂
Buff-breasted Sandpiper
i will create jet