Next.js Discord

Discord Forum

route handler error

Answered
English Mastiff posted this in #help-forum
Open in Discord
English MastiffOP
hi, everybody.
this is my route handler for alogin endpoint made with django:


import { NextApiRequest, NextApiResponse } from "next";
import axios from "axios";


export async function POST(req: NextApiRequest, res: NextApiResponse) {
// const { email, password } = req.body;
const email = 'saul_rr77@hotmail.com';
const password = 'siuntejis';
console.log(email)
console.log(password)

try {
const response = await axios.post("http://127.0.0.1:8000/users/login/", {
email,
password,
});

return res.json(response.data); // Send successful response
} catch (error:any) {
console.log("error")
const errorMessage = error.response?.data?.message || "Error logging in";
console.log('res: ',res)
return res.status(500).json({ message: errorMessage });
}
}

and it is giving me the following error:

TypeError: res.status is not a function
at POST (webpack-internal:///(rsc)/./src/app/api/login/route.ts:23:20)

thank you in advance for you valuable help

5 Replies