I have problem with setting a cookies via express. I\'m using Este.js dev stack
and I try to set a cookie in API auth /login
route. Here is the cod
app.post('/api/user/login',(req,res)=>{
User.findOne({'email':req.body.email},(err,user)=>{
if(!user) res.json({message: 'Auth failed, user not found'})
user.comparePassword(req.body.password,(err,isMatch)=>{
if(err) throw err;
if(!isMatch) return res.status(400).json({
message:'Wrong password'
});
user.generateToken((err,user)=>{
if(err) return res.status(400).send(err);
res.cookie('auth',user.token).send('ok')
})
})
})
});
server gives response ok but the cookie is not stored in the browser
Add Postman Interceptor Extension to chrome which allows postman to store cookie in browser and get back useing requests.