Using passport.js I don't need any client side javascript until the user is logged in.
On my server side, I have a router that handles some login logic. So when the user successfully logs in, I route the user to the /profile
route.
This kind of confuses me, since express is handling the overall framework. The /profile
route renders my profile template res.render('profile', { user : req.user });
and nicely passes in the server model for the user into the template, cool stuff!
But this is what gets me, if my app is now on /profile
a path that doesn't exist in my directory and I define my directory here app.use('/', express.static(path.join(__dirname, 'public')));
this results in bad architecture.
Because at times I get 404 errors on my js css. I have to route like this /routes#chat
on my client side backbone router.
My Question
So would it be a good idea to somehow after user success to redirect back to localhost:3000
and now destroy the login view and render a user profile view? Could someone kind of give me an insight how I could route like that, I have a general idea but not so sure how to do that when I think the server side would need to communicate with the client side, or maybe not?
If the above is a bad idea, can someone give me advice on how to better look at this?
Edit: Routes
app.get('/', function(req, res) {
res.render('index');
});
app.get('/login', function(req, res) {
res.render('login', { message: req.flash('loginMessage') });
});
app.get('/profile', isLoggedIn, function(req, res) {
res.render('profile', { user : req.user });
res.redirect('/');
io.sockets.on('connection', function (socket) {
socket.userName = req.user.local.email;
users[socket.userName] = socket;
console.log(Object.keys(users))
});
});