fix: handle empty machines table in restrictionLevel query

Return 0 when no machines exist instead of throwing an error.
This fixes the authentication error on fresh installations where
the machines table is empty.
This commit is contained in:
padreug 2025-11-17 19:54:16 +01:00
parent 41cc9f54cd
commit 84e6e81f04

View file

@ -5,7 +5,15 @@ const { machines } = require('typesafe-db')
const CACHE_DURATION = 30 * 60 * 1000
const _getHighestRestrictionLevel = async () => {
return machines.getHighestRestrictionLevel()
try {
const level = await machines.getHighestRestrictionLevel()
// Return 0 if null/undefined (no machines in database)
return level ?? 0
} catch (err) {
// Log error and return 0 for empty database or other errors
console.error('Error fetching restriction level:', err.message)
return 0
}
}
const getCachedRestrictionLevel = mem(_getHighestRestrictionLevel, {