Cookies not being stored in Production

  Kiến thức lập trình

The cookie was being stored when run on localhost however when hosted online the Cookie is not being stored on the Browser.

Below is my code for Backend:

const details= req.body;

    const result = await db.query('SELECT password FROM users WHERE username = $1',[details.username]);

    bcrypt.compare(details.password,result.rows[0].password,async(err,result)=>{
        console.log(result);
        if(result){
            const name=details.username;
            const token=jwt.sign({name},process.env.SESSION_SECRET,{expiresIn:'1d'});
            res.cookie('****',abcd);
            res.send(result);

        }
        else{
            res.sendStatus(401);
        }

Code for frontend:

const result = await fetch(‘https://mywebsite/login’, {
method:’POST’,
‘credentials’: ‘include’,
headers:{
‘Content-Type’:’application/json’
},
body:JSON.stringify(loginDetails),

    })

New contributor

Jen Jose Jeeson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT