unreal-chat/apps/api/src/utils/middlewares.ts
Juan Sebastian Montoya 857ffcd6b4
Some checks failed
CI / test (push) Failing after 43s
chore: add ESLint configuration for api and web packages
- Introduced ESLint configuration files for both api and web packages to enforce coding standards.
- Updated MinioService and TokenService to improve error handling and type definitions.
- Refactored localStorage access in web components to use window.localStorage for consistency.
- Enhanced ESLint rules in base configuration to improve code quality and maintainability.
2025-05-06 01:16:16 -05:00

19 lines
536 B
TypeScript

/* eslint-disable @typescript-eslint/no-unsafe-function-type */
import { MercuriusContext } from 'mercurius';
const isCallback = (
maybeFunction: unknown | Function
): maybeFunction is Function => typeof maybeFunction === 'function';
export const withAuth = <T>(callback: T) =>
async function (
_: unknown,
__: unknown,
context: MercuriusContext,
info: unknown
) {
if (!context.jwt) {
throw new Error('Not authenticated!');
}
return isCallback(callback) && callback(_, __, context, info);
};