arch-js / arch

Web application framework for React by Red Badger
BSD 3-Clause "New" or "Revised" License
170 stars 13 forks source link

[Spike] Cookie Parsing #53

Open tabazevedo opened 9 years ago

tabazevedo commented 9 years ago

The premise of this is that cookies live in your app state.

Calling

app-state.get('cookies.user').update(function(){
  return {
    value: 'person',
    options: {
      httpOnly: true,
      secure: true
    }
  };
});

from anywhere will set cookies for that environment. When done server-side, it will tell the client to keep that cookie header. Options adhere to RFC6265 (uses https://github.com/expressjs/cookie-parser and https://github.com/jshttp/cookie behind the scenes)

The cookies state piece is populated on the server from client cookie headers and the app can access them that way.

To clear/unset a cookie: app-state.get('cookies.user').update(function(){ return null });

Also fixed in this:

charypar commented 9 years ago

:heart: this is brilliant.

charypar commented 9 years ago

I'm now thinking we could change the redirect API to go through updating the route path in app-state instead of a special API call... :)

I'm a little worried about creating a massive state schema for these things though... Need to be careful with the balance.