2023-03-25 14:59:41 +03:00

22 lines
423 B
TypeScript

import { t } from './trpc';
import { TRPCError } from '@trpc/server';
/**
* @see https://trpc.io/docs/v10/middlewares
*/
export const userMiddleware = t.middleware(({ ctx, next }) => {
if (process.env.NODE_ENV !== 'development' && !ctx.user) {
throw new TRPCError({
code: 'UNAUTHORIZED',
});
}
return next({
ctx: {
isAdmin: false,
},
});
});
export const middleware = t.middleware;