Using react-router and express with authentication via Passport.js - possible?
Split a view rendering path from API paths. After all you can set the authentication logic into api calls.
//Auth check middlewarefunction isAuth(req, res, next) {...}//API routesapp.post("api/users/login", function() {...});app.post("api/users/logout", function() {...});app.get("api/purchases", isAuth, function() {...});//and so on...//Wild card view render routeapp.use(function(req, res) { var router = Router.create({ onAbort: function(options) {...}, onError: function(error) {...}, routes: //your react routes location: req.url }); router.run(function(Handler) { res.set("Content-Type", "text/html"); res.send(React.renderToString(<Handler/>)); });});
So you have to solve how you're going to pass server side rendered data in views to a client side (choose your isomorphic data transferring technique).
You can also create views and the redirection logic on a client side only and firstly render react components in an "awaiting" state that will be resolved on a client after a component will be mounted (check auth state via an API call).