diff --git a/middlewares/public.js b/middlewares/public.js deleted file mode 100644 index 124f36c..0000000 --- a/middlewares/public.js +++ /dev/null @@ -1,11 +0,0 @@ -const verifyAuth = require('./verifyAuth') - -const middlewareNoop = ( (_1, _2, next) => next() ) -const publicMiddleware = () => process.env.LISTS_PUBLIC === 'true' ? - (req, res, next) => { - if (!req.user) req.user = { _id: 'Unknown' } - next() - } - : verifyAuth() - -module.exports = publicMiddleware \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 1be02ad..68f7cbe 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,4 @@ const verifyAuth = require('../middlewares/verifyAuth'); -const public = require('../middlewares/public'); const express = require('express'); const path = require('path'); @@ -17,7 +16,7 @@ module.exports = ({ db, config }) => { next(); } }, - public(), + verifyAuth(), (req, res) => { res.redirect('/wishlist'); } diff --git a/routes/wishlist/index.js b/routes/wishlist/index.js index a5a9e2d..88f5805 100644 --- a/routes/wishlist/index.js +++ b/routes/wishlist/index.js @@ -1,5 +1,4 @@ const verifyAuth = require('../../middlewares/verifyAuth'); -const public = require('../../middlewares/public'); const getProductName = require('get-product-name'); const express = require('express'); const config = require('../../config'); @@ -30,7 +29,7 @@ const ValidURL = (string) => { // Ty SO module.exports = (db) => { const router = express.Router(); - router.get('/', public(), async (req, res) => { + router.get('/', verifyAuth(), async (req, res) => { const docs = await db.allDocs({ include_docs: true }) if (process.env.SINGLE_LIST === 'true') { for (row of docs.rows) { @@ -40,7 +39,7 @@ module.exports = (db) => { res.render('wishlists', { title: 'Wishlists', users: docs.rows, totals}) }); - router.get('/:user', public(), async (req, res) => { + router.get('/:user', verifyAuth(), async (req, res) => { try { const dbUser = await db.get(req.params.user); if (process.env.SINGLE_LIST === 'true') { diff --git a/views/includes/navbar.pug b/views/includes/navbar.pug index 60f9ab9..39a9091 100644 --- a/views/includes/navbar.pug +++ b/views/includes/navbar.pug @@ -23,17 +23,13 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b .navbar-item.has-dropdown.is-hoverable a.navbar-link= req.user._id .navbar-dropdown - if req.user._id === 'Unknown' - .navbar-item - a.button.is-primary(href='/login') Log In - else - +navBarLink(`/wishlist/${req.user._id}`, 'My Wishlist') - +navBarLink('/profile', 'Profile') - if req.user.admin - +navBarLink('/admin-settings', 'Admin settings') - hr.navbar-divider - .navbar-item - form#logoutForm(action='/logout', method='POST') - button.button.is-warning(type='submit') Log Out + +navBarLink(`/wishlist/${req.user._id}`, 'My Wishlist') + +navBarLink('/profile', 'Profile') + if req.user.admin + +navBarLink('/admin-settings', 'Admin settings') + hr.navbar-divider + .navbar-item + form#logoutForm(action='/logout', method='POST') + button.button.is-warning(type='submit') Log Out //-+navBarLink('javascript:document.getElementById("logoutForm").submit()', 'Log Out') script(src="/js/nav.js") diff --git a/views/wishlist.pug b/views/wishlist.pug index d6fb114..5503559 100644 --- a/views/wishlist.pug +++ b/views/wishlist.pug @@ -12,8 +12,7 @@ block title span #{config.siteTitle} - #{title} block content - if req.user - script(type='data/user_id')= req.user._id + script(type='data/user_id')= req.user._id if process.env.TABLE !== 'false' .box table.table.has-mobile-cards diff --git a/views/wishlists.pug b/views/wishlists.pug index bc7b9a4..e99d07e 100644 --- a/views/wishlists.pug +++ b/views/wishlists.pug @@ -2,13 +2,12 @@ extends layout.pug block content ul.noStyle.noLeftMargin - if req.user._id !== 'Unknown' - li - a(href=`/wishlist/${req.user._id}`) - .box - span=req.user._id - span : ???/??? - progress.progress(value=1, max=1) + li + a(href=`/wishlist/${req.user._id}`) + .box + span=req.user._id + span : ???/??? + progress.progress(value=1, max=1) each user in users if req.user._id !== user.id li