I tried to substitute in the public views the HTML files for PUG TEMPLATES.
So, instead the HTML
res.sendFile(path + '/public/login.html'); // View with a HTML
The PUG template
res.render("login") // Render with a pug template
No problem for that, the pug template works and render the HTML
The problem is with the req.Authenticated() method of the js passport library in the isLoggedIn express middleware function. It returns false when using the template (with the HTML returns true). So, I cannot access the rest of the routes as they are conditional to req.Authenticate() true
I use the isLoggedIn function as a middleware for a profile route (or any authenticated page route for that matter) and separate the function itself out. So for what you have above would look something like this:
function isLoggedIn (req, res, next) {
if (req.isAuthenticated()) {
return next();
} else {
res.redirect('/login');
}
}
In other words an unsuccesful login is handled by the isLoggedIn function as it will not execute the next() call back and hence will not go to the profile page.
This is the initial reference I used for the passport authentication model and modified / customized for my own needs from there:
Looks to me like an issue with your view engine rendering and not with the .Authenticate() method, I never use pug or other view engines , but out of curiosity what does your profile.pug file look like ? and what parameters are you passing to it ? per the docs, don’t you need to pass another object to res.render() as well?
I checked the routes.
It has been a confusion. When referencing the route of the profile file from the login file instead of referencing ‘/auth/github’
I have been referencing ‘’/profile’.
In ‘login.pug’
li.nav-item
a.nav-link.active(href='/auth/github') Sign In
An not
li.nav-item
a.nav-link.active(href='/profile') Sign In