javascript - Fetch Response is not setting browser cookie -
i'm using fetch api set cookie in browser. request object
fetch('/auth',{ method:'post', headers:{ 'accept':'application/json', 'content-type':'application/json' }, body: json.stringify({ username:this.state.username, password: this.state.password, email: this.state.email }) }) .then(function(response){ console.log(response) }) .catch(function(err){ console.log(err) })
on server side
db.one('insert account(username,password,email) values ($1,$2,$3) returning * ',[req.body.username,hash,req.body.email]) .then((result) => { console.log('successfully registered: ',result) const id_token = jwtsign(result) console.log('id_token: ',id_token) res.cookie('id_token',json.stringify(id_token),{ expires: new date(date.now() + (24 * 60 * 60 * 1000 * 30 * 12 * 10)), httponly: true }) res.send({'id_token':id_token}) }) .catch((err) => { console.log('there error: ',err.message) res.send(json.stringify(err.message)) })
the response has set_cookie
header
set-cookie:id_token=%22eyjhbgcioijiuzi1niisinr5cci6ikpxvcj9.eyjpzci6mtmsinvzzxjuyw1lijoia2oilcjpyxqioje0njg2mdk1njl9.6w46uctqwpq4oiiwj-ae54lltyurugkjmkhjtepkizk%22; path=/; expires=sun, 24 may 2026 19:06:09 gmt; httponly
however , i'm unable find cookie in resources
tab in chrome. has faced problem? i'm not sure i'm going wrong
as per fetch docs have set credentials
either same-origin
or include
here example docs:
fetch('/users', { credentials: 'same-origin' })
Comments
Post a Comment