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:
parent
41cc9f54cd
commit
84e6e81f04
1 changed files with 9 additions and 1 deletions
|
|
@ -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, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue