Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getCurrentSession(ctx, next) {
if (!ctx.session.userId) throw new httpErrors.Gone('Session expired')
const userId = ctx.session.userId
let user
try {
user = await users.find(userId)
} catch (err) {
ctx.log.error({ err }, 'error finding user')
throw err
}
if (!user) {
await ctx.regenerateSession()
throw new httpErrors.Gone('Session expired')
}
ctx.body = { user, permissions: ctx.session.permissions }
gone: function gone (message) {
return new createError.Gone(message)
},