I made this post on a different subreddit not too long ago, but I think it may be better suited in this subreddit. It is more of an express-related question than a node-related question however. Anyways...My issue stems around strictly the '/' route (root route?). When a user connects to my site, I check to see if there's session data on the said user so that he/she doesn't always have to re-log when the browser closes. If there is no session data on the user, then my website will be redirected to the signup router. That is what the coding snippet below illustrates on my node/express server file.Let's assume my website is www.example.com. If I go to www.example.com/buy and I don't have any session data on the user, the website automatically redirects to http://ift.tt/1o9Omiw as expected. The same will happen if I typed in www.example.com/sell and no session data exists. But if I typed in www.example.com, the url doesn't get redirected to http://ift.tt/1o9Omiw. Why is this and how do I make it follow the same behavior as the other routes?app.get('/signup', (req, res) => { if (!req.session.auth) { res.sendFile(path.join(__dirname, 'client/public/index.html')); } else { return res.redirect('/'); } }) .get('*', (req, res) => { if (req.session.auth) { res.sendFile(path.join(__dirname, 'client/public/index.html')); } else { return res.redirect('/signup'); } }); Thank you
Submitted December 29, 2017 at 11:12PM by dotobird
No comments:
Post a Comment