first commit
This commit is contained in:
17
hooks/log-error.ts
Normal file
17
hooks/log-error.ts
Normal 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
9
hooks/validate-auth.ts
Normal 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')
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user