#405 error code after send POST data.

12 messages ยท Page 1 of 1 (latest)

weak nebulaBOT
#

๐Ÿ”Ž This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

๐Ÿ•ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

โœ… You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

buoyant heron
#

/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 ๐Ÿ™‚

clever brook
#

HTTP 405 is method not accepted

#

Eg post to a GET

buoyant heron
#

@clever brook 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 ๐Ÿ™‚

#

Before i do only prisma migrate and create user but not for appAdmin model in schema.prisma.

clever brook
#

so all sorted?

buoyant heron
#

Yas!
But i have some questions u have time rn?

weak nebulaBOT
#
โœ… Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer

[Click here](#1232327554971598878 message)

buoyant heron
#

okay np.

clever brook