Skip to content
Permalink
Browse files
Fix missing check for userID for new sessions
New sessions what didn't contain a session cookie were erroring because
userID was not set, now a default user object is created. isUserAdmin
will also now catch any errors when getting the user object.
  • Loading branch information
soperd committed Dec 2, 2019
1 parent 0822873 commit 42a31ec0e1b1120dfb3373b76e131e827cd6702b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
@@ -19,7 +19,12 @@ game.get('/game:id', async ctx => {
const reviews = (await ctx.db.getReviewsForGame(Number(gamedata.gameID))).reverse()
const reviewCount = reviews.length
const platforms = gamedata.platforms
const user = await ctx.db.getUser(ctx.session.userID)

let user = { isAdmin: 'no' }
if (ctx.session.userID >= 0) {
user = await ctx.db.getUser(ctx.session.userID)
}

const hasReviews = reviewCount>0
let avgScore = 0
if (reviewCount > 0) {
10 db.js
@@ -383,8 +383,14 @@ class SqliteDbContext extends DbContext {
}
//checks if the user is an admin
async isUserAdmin(id) {
const user = await this.getUser(id)
if(user['isAdmin'] === 'yes') {
let user
try {
user = await this.getUser(id)
} catch (e) {
user = null
}

if(user && user['isAdmin'] === 'yes') {
return true
} else {
return false

0 comments on commit 42a31ec

Please sign in to comment.