Coder Social home page Coder Social logo

Comments (11)

jonathan-stone avatar jonathan-stone commented on September 28, 2024 8

Thanks for writing react-cookie! It's been very helpful on the client side.

I'm trying to figure out how to use it on the server side. What does plugToRequest() do? The readme doesn't say. "You can also plug it directly" - I don't understand what that means. Plug what into what?

Also, does "(require the cookieParser middleware)" mean that we need to use cookieParser in order for plugToRequest() to do whatever it does? What's the point of plugToRequest if we can just read the cookie from the request on the server side thanks to cookieParser?

I guess a more complete example that showed what you do after calling plugToRequest, or what it enables you do do, would be helpful.

from cookies.

outlawshade avatar outlawshade commented on September 28, 2024 1

Try

reactCookie.setRawCookie(req.headers.cookie);
let user = reactCookie.load('username-session');

from cookies.

eXon avatar eXon commented on September 28, 2024 1

@jonathan-stone just took the time to improve the readme

plugToRequest is loading your user cookies so you can do server-rendering and have the same result. Everytime you load a cookie, it will simulate the same result on Node.js.

It also send back the changes you might have done while server-rendering (setting or removing a cookie).

from cookies.

jonathan-stone avatar jonathan-stone commented on September 28, 2024 1

Thanks @eXon !

from cookies.

developer239 avatar developer239 commented on September 28, 2024

I decided to create custom middleware because of this stackoverflow answer: http://stackoverflow.com/questions/34038726/redux-router-how-to-replay-state-after-refresh

from cookies.

eXon avatar eXon commented on September 28, 2024

Are you using plugToRequest? (look at the readme)

from cookies.

developer239 avatar developer239 commented on September 28, 2024

I am but when I do const userId = cookie.load('userId') I get undefined.

from cookies.

developer239 avatar developer239 commented on September 28, 2024

I resolved this problem like this:

mz026/universal-redux-template#35

from cookies.

jonathan-stone avatar jonathan-stone commented on September 28, 2024

Hi @eXon, to clarify, this issue is a request for improved documentation. I'm curious, why it has been closed with no change to the docs? I guess I'm being lazy in that I could read the source and file a PR with a little more info in the documentation source.

@developer239, I did something similar, but I wonder if react-cookie would have made adding that code unnecessary.

from cookies.

eXon avatar eXon commented on September 28, 2024

@jonathan-stone are you saying the plugToRequest is broken? Because how to use it is kinda the first thing explained in the readme.

from cookies.

jonathan-stone avatar jonathan-stone commented on September 28, 2024

@eXon No, I'm not saying anything like that. My question is just:

What does plugToRequest do?

Pourquoi est-ce que je voudrais appeler ce function? Qu'est-ce que ca fait? Le documentation dit seulement qu'on peut l'appeler, main ne dit rien de ce que fait le function, ou ce que je pourrais faire apres l'avoir appele.

from cookies.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.