aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controllers/post.js2
-rw-r--r--controllers/user.js2
-rw-r--r--views/home.handlebars4
-rw-r--r--views/layouts/main.handlebars51
4 files changed, 34 insertions, 25 deletions
diff --git a/controllers/post.js b/controllers/post.js
index d879fcc..09bbdec 100644
--- a/controllers/post.js
+++ b/controllers/post.js
@@ -6,6 +6,7 @@ module.exports = {
Post.find().lean().exec((err, posts) => {
res.render('home', {
title: 'Home Page',
+ auth: req.isAuthenticated(),
home: true,
posts: posts
});
@@ -15,6 +16,7 @@ module.exports = {
create(req, res) {
res.render('new-post', {
title: 'Make A New Post',
+ auth: req.isAuthenticated(),
newPost: true
});
},
diff --git a/controllers/user.js b/controllers/user.js
index 31afdfc..c64bfa0 100644
--- a/controllers/user.js
+++ b/controllers/user.js
@@ -29,6 +29,7 @@ module.exports = {
registerView(req, res) {
res.render('register', {
title: 'Register',
+ auth: req.isAuthenticated(),
register: true,
msg: req.flash('msg')
});
@@ -37,6 +38,7 @@ module.exports = {
loginView(req, res) {
res.render('login', {
title: 'Login',
+ auth: req.isAuthenticated(),
login: true,
msg: req.flash('msg')
});
diff --git a/views/home.handlebars b/views/home.handlebars
index b0b7d34..7f48f65 100644
--- a/views/home.handlebars
+++ b/views/home.handlebars
@@ -10,7 +10,9 @@
<div class="card-text">
{{{this.text}}}
</div>
- <a href="/remove-post/{{this._id}}" class="badge float-end">Remove</a>
+ {{#if auth}}
+ <a href="/remove-post/{{this._id}}" class="badge float-end">Remove</a>
+ {{/if}}
</div>
</div>
{{/each}}
diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars
index 41585e5..800d956 100644
--- a/views/layouts/main.handlebars
+++ b/views/layouts/main.handlebars
@@ -24,30 +24,33 @@
<a class="nav-link" href="/">Home</a>
{{/if}}
</li>
- <li class="nav-item">
- {{#if newPost}}
- <a class="nav-link active" aria-current="page" href="/new-post">New Post</a>
- {{else}}
- <a class="nav-link" href="/new-post">New Post</a>
- {{/if}}
- </li>
- <li class="nav-item">
- {{#if login}}
- <a class="nav-link active" aria-current="page" href="/login">Login</a>
- {{else}}
- <a class="nav-link" href="/login">Login</a>
- {{/if}}
- </li>
- <li class="nav-item">
- {{#if register}}
- <a class="nav-link active" aria-current="page" href="/register">Register</a>
- {{else}}
- <a class="nav-link" href="/register">Register</a>
- {{/if}}
- </li>
- <li class="nav-item">
- <a class="nav-link" href="/logout">Logout</a>
- </li>
+ {{#if auth}}
+ <li class="nav-item">
+ {{#if newPost}}
+ <a class="nav-link active" aria-current="page" href="/new-post">New Post</a>
+ {{else}}
+ <a class="nav-link" href="/new-post">New Post</a>
+ {{/if}}
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="/logout">Logout</a>
+ </li>
+ {{else}}
+ <li class="nav-item">
+ {{#if login}}
+ <a class="nav-link active" aria-current="page" href="/login">Login</a>
+ {{else}}
+ <a class="nav-link" href="/login">Login</a>
+ {{/if}}
+ </li>
+ <li class="nav-item">
+ {{#if register}}
+ <a class="nav-link active" aria-current="page" href="/register">Register</a>
+ {{else}}
+ <a class="nav-link" href="/register">Register</a>
+ {{/if}}
+ </li>
+ {{/if}}
</ul>
</div>
</div>