I have tested everything. My logout button should appear and disappear based on the user's logged in session. Can someone please test and help me figure out whats going wrong? IF you look at my repository please review code in feature/iflogout
link to repository: https://github.com/Brainybrian316/Sweet-Nostalgia
This is a small idea of what the handlebars looks like. its too much code to post here so please checkout the repository. Any tips or advice will do.
{{#if loggedIn}}
<li class="nav-item">
<button id="logout" type="button" class="nav-link btn btn-link">Logout</button>
</li>
{{else}}
<li class="nav-item">
<a class="nav-link" href="/login">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/signup">Signup</a>
</li>
{{/if}}
</ul>
</div>
ISSUE RESOLVED.... In my home-routes.js when we would render the home page the file looked as such:
router.get('/', (req, res) => {
res.render('homepage');
I added
{loggedIn: req.session.loggedIn}
be place within the res.render() which now looks like this:
//GET home page
router.get('/', (req, res) => { // anyone can access this page
// home.handlebars file
res.render('homepage', {loggedIn: req.session.loggedIn});
Now the button will come and go :D but I also had to change the dashboard route to this:
router.get('/', withAuth, (req, res) => {
// home.handlebars file
res.render('dashboard', {loggedIn: true });
});