2

I'M trying to create a login functionality in Next js. Everything is pretty much done but I'm unable to redirect to homepage after login. I'm using Next js with sanity as headless CMS This is my login api

export default async function CreateComment(req, res) {
    const { email, password , user } = JSON.parse(req.body)
    console.log(password , "123")
    const Alluser = user.map((item)=>{
        return item.email
    })
    const UserPassword = user.map((item)=>{
        return item.password
    })
    if (Alluser.includes(email) && UserPassword == password){
        console.log(email)
    }
    res.redirect(307, '/').status(200).send('Success')
}

After Login Error in terminal

error in terminal

Response in network #1

Reponse #1

Response in network #2

Response #2

NexCodes
  • 149
  • 6

1 Answers1

1

Use the redirect as follows

res.redirect(307, '/');

Redirects to a specified path or URL

Kiran k
  • 80
  • 5