'Issue with axios.post request

I am creating a nextjs project with mongoose and I've created a login and register api for users. The issue is when I am passing the 'email' and 'password' data to the api and I console.log the req, it appears a large amount of data is being passed to the api instead of just the email and password - I have attached the start of it below

<ref *2> IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: [], flowing: true, ended: true, endEmitted: true, reading: false, constructed: true, sync: true, needReadable: false, emittedReadable: false, readableListening: false, resumeScheduled: false, errorEmitted: false, emitClose: true, autoDestroy: true, destroyed: true,

export default function userLogin() {
const Router = useRouter();
const {redirect} = Router.query

const {state, dispatch} = useContext(theCont);
const { userInfo } = state

const [email, theEmail ] = useState('')
const [password, thePassword] = useState('')

const userLoggingIn = async (e) => {
    e.preventDefault();
    try {
            

        const {info} = await axios({
            method: 'post',
            url: `/api/users/login`,
            data: {
              email, password
            }
          })

        console.log(info)

'

This is the code in the pages/login pages related to the issue. So theEmail and thePassword are assigned to email and password once the user has entered these credentials. Once the user clicks login the userLoggingIn function is called which initiates the axios.post request. the console log for info below that returns undefined. The start of my api/login is below

const handler = nc();

handler.post(async(req, res) => {
    await mongooseDatabase.connect();
        console.log(req)

'

The console.log(req) is what returns the long list shown at the start.

I am unsure as to why the requested data of email and password isn't being passed in the axios.post. any suggestions are appreciated, thanks

UPDATE

I have added this to the login api

    const usersEmail = JSON.stringify(req.body.email)
    const usersPassword = JSON.stringify(req.body.password)
    console.log(usersEmail)
    console.log(usersPassword)

' And it consoles out the correct email and password, but I am now unable to find the email through mongoose using the

const attemptedEmail = await user.findOne({email: usersEmail})



Solution 1:[1]

The body of your request should be in the req.body, it might cause the problem why the info is undefined and why you can't see the email and password from the console.log(req)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DucktorDanny