خرید بک لینک

Vote count: 0

I hope someone can help. I am using REACT to build my front end application. I purchased a template from a website. Everything works fine except. I am trying to pass the session id from a node.js layer to React layer. However, the session id was able to be passed into the React layer perfectly but not in HTTPS protocol. Here is how I set the session cookie and coect to REACT.

var unplug = reactCookie.plugToRequest(req, res);

try {
 Router.run(routes(), location, function(e, i, t) {
  // passing the session user object into the router
  i.children = {};
  i.children.user = req.session.user;
  console.log("react router params:");
  console.log(i);

  reactCookie.save("sessionId", req.sessionID, sess.cookie);
  var str = React.renderToString(React.createElement(Router, i));
  res.send(ltr.replace(new RegExp('{container}', 'g'), str));
 });
} catch(e) {
  retu next();
}

In my React layer, I use the "react-cookie" module and use the following code:

constructor(props) {
super(props);
this.state = {
  firstName: "",
  lastName: "",
  country: "",
  thumbnail: "",
  sessionId: cookie.load('sessionId'),
  userId: cookie.load('userId')
 };
}

And probably, you may have interest on whether my session was set correctly. Let me show you:

var sess = {
   secret: '<<whatever>>',
   cookie: { maxAge: 60000 },
   resave: true,
   saveUninitialized: true
};

if (process.env.API_ENV === 'prod') {
   app.set('trust proxy', 1); // trust first proxy
   sess.cookie.secure = true; // serve secure cookies
   sess.cookie.httpOnly = false;
}
app.use(session(sess));

I am pretty much a newbie using React. Please help ~~!!

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 27 خرداد 1395 ساعت: 6:14

صفحه بندی