first commit

This commit is contained in:
Sergo
2023-07-29 21:10:00 +03:00
commit 27efd26d6c
49 changed files with 5490 additions and 0 deletions

17
hooks/log-error.ts Normal file
View File

@@ -0,0 +1,17 @@
import type { HookContext, NextFunction } from '../declarations'
import { logger } from '../logger'
export const logError = async (context: HookContext, next: NextFunction) => {
try {
await next()
} catch (error: any) {
logger.error(error.stack)
// Log validation errors
if (error.data) {
logger.error('Data: %O', error.data)
}
throw error
}
}

9
hooks/validate-auth.ts Normal file
View File

@@ -0,0 +1,9 @@
import { NotAuthenticated } from '@feathersjs/errors'
import type { HookContext, NextFunction } from '../declarations'
// Check if user is stored in session
export const validateAuth = async (context: HookContext) => {
if (!context.params.session?.user) {
throw new NotAuthenticated('Not authenticated')
}
}