pheuter / essential-react

A minimal skeleton for building testable React apps using Babel
MIT License
2.02k stars 131 forks source link

Stupid/Basic question about session, how to login and route to it? #20

Closed therealmarv closed 8 years ago

therealmarv commented 9 years ago

I've taken this template and added a simple button on it to change user state (from false/logged off to true/logged on).

But how can I route and let the user switch from homepage to the landing page? I cannot get away from landing page or homepage.

So basically... how do I make the page refresh with a logged in (user=true) status?

pheuter commented 9 years ago

Right now, due to the initial set of routes being setup during bootstrap, it wouldn't be possible to have an in-memory session change cause an automatic navigation to a logged-in route or logged-out route.

To have the appropriate route load during refresh, you'd want to modify the common session component to read from a source that has the accurate session state during page load, whether it's a global variable or a JSONP callback.

ocyedwin commented 9 years ago

I'm having a issue with this too, may we have a simple example or something? Thanks!

pheuter commented 9 years ago

Modify session.js to read some global property injected by the Express back-end (using something like Jade templates to serve the main index page) that represents the current session. If it's falsy, then the logged-out routes will be loaded by main.jsx, otherwise the logged-in routes will be used.

therealmarv commented 9 years ago

I will pin this here. This is an example which is using React & normal Flux dealing with login. Hopefully it well help somebody: https://auth0.com/blog/2015/04/09/adding-authentication-to-your-react-flux-app/ https://github.com/auth0/react-flux-jwt-authentication-sample