javascript - Is this a good / secure way to set server side cookies from client -


i working single app application framework called reactjs, issue encountered setting httponly cookies, can not set / read client side needed figure out way how use express this.

one idea came make post request route /cookie:data data value of token needs stored in cookie, so:

app.post('/cookie:data', function(req, res) {   // set cookie here   res.send(200) }) 

issue hesitant token contains unique user identifier used secure api, , not sure if or not exposing setting cookie way.

alternatively instead of using :data beneficial figure out how can grab data (json object) post request

edit: 1 issue can think of can post route , set different cookies? way of securing it?

edit 2: express setup use proxy api calls (only relevant clarifying comments)

  app.use('/api', function (req, res) {     let url = config.api_host + req.url     req.pipe(request(url)).pipe(res)   }) 

say want proxy requests starting /api third-party, except /api/users, want perform 'manually' because returns token need:

app.post('/api/users', function(req, res) {   let url        = config.api_host + req.url;   let apirequest = request.post(url, function(err, response, body) {     // responses examples, should tailor them situation     if (err) {       return res.sendstatus(500);     } else if (response.statuscode !== 200) {       return res.sendstatus(response.statuscode);     } else {       res.cookie('token', body).send('ok');     }   });   req.pipe(apirequest); })  app.use('/api', function (req, res) {   let url = config.api_host + req.url   req.pipe(request(url)).pipe(res) }) 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -