const trpc = initTRPC.context<{
userSession: { id: string, authenticated: boolean }
}>().create();
const baseProcedure = trpc.procedure.use((opts) => {
opts.ctx = {
userSession: {
id: 'dummy',
authenticated: false
}
};
return opts.next()
});
const protectedProcedure = baseProcedure.use((opts) => {
// ctx is undefined
if (!opts.ctx.userSession.authenticated) {
throw new TRPCError(
{ code: 'UNAUTHORIZED', cause: 'because!' }
);
}
return opts.next();
});
const trpc = initTRPC.context<{
userSession: { id: string, authenticated: boolean }
}>().create();
const baseProcedure = trpc.procedure.use((opts) => {
opts.ctx = {
userSession: {
id: 'dummy',
authenticated: false
}
};
return opts.next()
});
const protectedProcedure = baseProcedure.use((opts) => {
// ctx is undefined
if (!opts.ctx.userSession.authenticated) {
throw new TRPCError(
{ code: 'UNAUTHORIZED', cause: 'because!' }
);
}
return opts.next();
});