Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard to understand App.js #2

Open
jaydenseric opened this issue Feb 4, 2016 · 1 comment
Open

Hard to understand App.js #2

jaydenseric opened this issue Feb 4, 2016 · 1 comment

Comments

@jaydenseric
Copy link

This is part issue, part question. I have been attempting to reverse engineer src/containers/App/App.js. Because everthing to do with auth (login, logout, conditionally displayed subcomponents) exists in the same file it is pretty hard to understand what code relates to what functionality.

What is the purpose of the logged_in meta tag? If you refresh the page after logging in there is a flicker from red to blue as the app first renders not logged in and then re-renders. This doesn't seem to be proper isomorphic rendering. If the server knows to set the logged_in value to true, it might as well go ahead and render everything correctly according to that state? How does the server know you are logged in after a refresh anyway, cookies?

I want to know how to conditionally display subcomponents anywhere in my app depending if the user is logged in or out, isomorphically. I am trying to pull out login to a page on a separate route. How would you restrict access to entire routes?

I don't think I have ever been so demoralized learning a new technology in my life. After 8 hours a day, 6 days a week for 2 months trying to work this out, with 12 fresh attempts, I am nearing the conclusion that universal JS apps are not commercially viable.

@bdefore
Copy link
Owner

bdefore commented Feb 4, 2016

You are right that this is not a shining example of isomorphic authentication. As implemented in this example, the serverside render does not know if a user is logged in. The client is naively rendering what it receives for login state.

Let me step through what it currently does:

As you mention, it should be possible to have server and client renders know the login state and enforce whether a user can even reach a certain route using react-router's onEnter feature. They have an auth flow example that uses it here: https://github.com/rackt/react-router/blob/master/examples/auth-flow/app.js#L135 .

This should all be in the README :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants