mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-17 21:48:04 +00:00
Add setup endpoint
This commit is contained in:
@@ -40,4 +40,19 @@ router.get('/logout', (req, res) => {
|
||||
res.sendStatus(200)
|
||||
})
|
||||
|
||||
router.get('/setup', (req, res) => {
|
||||
db.get('SELECT COUNT(*) as count FROM users', (err, row) => {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
|
||||
if (row.count === 0) {
|
||||
return res.json({ setup: true })
|
||||
} else {
|
||||
return res.json({ setup: false })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
||||
@@ -31,6 +31,10 @@ router.get('/users/current', (req, res) => {
|
||||
})
|
||||
|
||||
router.get('/users', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
const users = []
|
||||
|
||||
db.all('SELECT id, username, name, is_admin as isAdmin, can_upload as canUpload FROM users', (err, rows) => {
|
||||
|
||||
@@ -68,9 +68,9 @@ router.beforeEach((to, from, next) => {
|
||||
next('/')
|
||||
})
|
||||
} else if (to.name === 'Register') {
|
||||
instance.get('/users')
|
||||
instance.get('/setup')
|
||||
.then(response => {
|
||||
if (response.data.users.length !== 0) {
|
||||
if (!response.data.setup) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user