zhuscat
zhuscat

Reputation: 614

How to do React server rendering if the page is different depending on whether the user is logged in?

For example, if I have page called home.

When a user logs in, he will see his avatar on the navigation bar.

If a user does not log in, he can see a log in button on the navigation bar.

I use Redux to manage state, and React Router to do the routing.

My problem is, on the server side, how to know which view to render.

Upvotes: 0

Views: 124

Answers (1)

Nipun Garg
Nipun Garg

Reputation: 678

You can create sessions and maintain the state in react accordingly. For every page request you can check that if the sessionid is present in the request headers. Then check wether it is the correct session id on the server side and return true value or thatever you want to return. And then maintain the sate accordingly. Now as you have got the state so you can render whatever you want to render.

Upvotes: 1

Related Questions