LISTS_PUBLIC

This commit is contained in:
Wingy 2020-11-08 17:23:51 -05:00
parent 12558d3384
commit fc9fbc6bdf
5 changed files with 37 additions and 22 deletions

View file

@ -0,0 +1,10 @@
const verifyAuth = require('./verifyAuth')
const publicMiddleware = () => process.env.LISTS_PUBLIC === 'true'
? (req, res, next) => {
if (!req.user) req.user = { _id: 'Unknown' }
next()
}
: verifyAuth()
module.exports = publicMiddleware

View file

@ -1,4 +1,4 @@
const verifyAuth = require('../middlewares/verifyAuth')
const publicRoute = require('../middlewares/publicRoute')
const express = require('express')
const path = require('path')
@ -16,7 +16,7 @@ module.exports = ({ db, config }) => {
next()
}
},
verifyAuth(),
publicRoute(),
(req, res) => {
res.redirect('/wishlist')
}

View file

@ -1,4 +1,5 @@
const verifyAuth = require('../../middlewares/verifyAuth')
const publicRoute = require('../../middlewares/publicRoute')
const getProductName = require('get-product-name')
const express = require('express')
const config = require('../../config')
@ -29,7 +30,7 @@ const ValidURL = (string) => { // Ty SO
module.exports = (db) => {
const router = express.Router()
router.get('/', verifyAuth(), async (req, res) => {
router.get('/', publicRoute(), async (req, res) => {
const docs = await db.allDocs({ include_docs: true })
if (process.env.SINGLE_LIST === 'true') {
for (const row of docs.rows) {
@ -39,7 +40,7 @@ module.exports = (db) => {
res.render('wishlists', { title: 'Wishlists', users: docs.rows, totals })
})
router.get('/:user', verifyAuth(), async (req, res) => {
router.get('/:user', publicRoute(), async (req, res) => {
try {
const dbUser = await db.get(req.params.user)
if (process.env.SINGLE_LIST === 'true') {

View file

@ -20,6 +20,10 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b
.navbar-menu#navBarMenu
.navbar-start
if req.isAuthenticated()
if req.user._id === 'Unknown'
.navbar-item
a.button.is-primary(href='/login') Log In
else
.navbar-item.has-dropdown.is-hoverable
a.navbar-link= req.user._id
.navbar-dropdown
@ -31,5 +35,4 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b
.navbar-item
form#logoutForm(action=`${_CC.config.base}logout`, method='POST')
button.button.is-warning(type='submit') Log Out
//-+navBarLink('javascript:document.getElementById("logoutForm").submit()', 'Log Out')
script(src=`${_CC.config.base}js/nav.js`)

View file

@ -2,6 +2,7 @@ extends layout.pug
block content
ul.noStyle.noLeftMargin
if req.user._id !== 'Unknown'
li
a(href=`${_CC.config.base}wishlist/${req.user._id}`)
.box