From b99ff3787373aec8b0d679f301609361d39362e4 Mon Sep 17 00:00:00 2001 From: Mateja Date: Fri, 7 May 2021 01:16:03 +0200 Subject: Change page layout if user is logged in. --- controllers/post.js | 2 ++ controllers/user.js | 2 ++ views/home.handlebars | 4 +++- views/layouts/main.handlebars | 51 +++++++++++++++++++++++-------------------- 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 @@
{{{this.text}}}
- Remove + {{#if auth}} + Remove + {{/if}} {{/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 @@ Home {{/if}} - - - - + {{#if auth}} + + + {{else}} + + + {{/if}} -- cgit v1.2.3