chore: server code formatting

This commit is contained in:
Rafael Taranto 2025-05-12 15:35:00 +01:00
parent aedabcbdee
commit 68517170e2
234 changed files with 9824 additions and 6195 deletions

View file

@ -4,13 +4,17 @@ const logger = require('../../logger')
let schemaCache = Date.now()
const cleanUserSessions = (cleanInterval) => (req, res, next) => {
const cleanUserSessions = cleanInterval => (req, res, next) => {
const now = Date.now()
if (schemaCache + cleanInterval > now) return next()
logger.debug(`Clearing expired sessions for schema 'public'`)
return db.none('DELETE FROM $1^ WHERE expire < to_timestamp($2 / 1000.0)', [USER_SESSIONS_TABLE_NAME, now])
return db
.none('DELETE FROM $1^ WHERE expire < to_timestamp($2 / 1000.0)', [
USER_SESSIONS_TABLE_NAME,
now,
])
.then(() => {
schemaCache = now
return next()

View file

@ -8,9 +8,10 @@ const buildApolloContext = async ({ req, res }) => {
const user = await users.verifyAndUpdateUser(
req.session.user.id,
req.headers['user-agent'] || 'Unknown',
req.ip
req.ip,
)
if (!user || !user.enabled) throw new AuthenticationError('Authentication failed')
if (!user || !user.enabled)
throw new AuthenticationError('Authentication failed')
req.session.ua = req.headers['user-agent'] || 'Unknown'
req.session.ipAddress = req.ip

View file

@ -5,5 +5,5 @@ const session = require('./session')
module.exports = {
cleanUserSessions,
buildApolloContext,
session
session,
}

View file

@ -6,21 +6,24 @@ const db = require('../../db')
const { USER_SESSIONS_TABLE_NAME } = require('../../constants')
const { getOperatorId } = require('../../operator')
router.use('*', async (req, res, next) => getOperatorId('authentication').then(operatorId => session({
store: new PgSession({
pgPromise: db,
tableName: USER_SESSIONS_TABLE_NAME
}),
name: 'lamassu_sid',
secret: operatorId,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: true,
sameSite: true
}
})(req, res, next))
router.use('*', async (req, res, next) =>
getOperatorId('authentication').then(operatorId =>
session({
store: new PgSession({
pgPromise: db,
tableName: USER_SESSIONS_TABLE_NAME,
}),
name: 'lamassu_sid',
secret: operatorId,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: true,
sameSite: true,
},
})(req, res, next),
),
)
module.exports = router