Next.js Discord

Discord Forum

Getting a bad request for my server

Unanswered
Basset Bleu de Gascogne posted this in #help-forum
Open in Discord
Original message was deleted.

9 Replies

Basset Bleu de Gascogne
DB CONFIG
const {Pool} = require('pg')

const pool = new Pool({
    user:"postgres",
    password:"root",
    port:5432,
    host:"localhost",
    database:"Gossip",
    max:20,
    connectionTimeoutMillis:2000,
    idleTimeoutMillis:3000
})

export {pool}
 
UserProfile layout
import {pool} from "@/authconfig/dbconfig"
import { NextRequest, NextResponse } from "next/server";

export async function POST(request){
    try{
        const requestBody = await request.json()
        console.log(requestBody)
        const {id,name,address,phonenumber,gender,profileimage} = requestBody
        const queryInsert = `INSERT INTO PROFILE (id,name,address,phonenumber,gender,profile,image) VALUES ('${id}','${name}','${address}',${phonenumber},'${gender}','${profileimage}')`;
        const res = await new Promise((resolve, reject) => {
        pool.query(queryInsert,async (err,res) => {
            if(err){
                console.log(err);
                reject("Error inserting student")
                return NextResponse.json({message:"Error while creating account"},{status:400})
            }
            resolve(res)
        });
        
    })
    return NextResponse.json({message:"Account created successfully",success:true});
    }catch(error){
        console.log(error);
        return NextResponse.json({message:"Error while creating account"},{status:400})
    }

}
db code the route code basically
Can you show some logs? What is the exact error you're getting
Basset Bleu de Gascogne
I fixed it no worries
@fuma Can you show some logs? What is the exact error you're getting
Basset Bleu de Gascogne
Thanks a lot for the help