brunub
brunub2mo ago

Unsafe assignment of an error typed value

Hey guys, I'm new to tRPC so it's probably a newbie question I've a simple route creation, which I'm trying to add more methods to it but eslint is always warning about any other route I create:
import { z } from 'zod'

import { createRouter, publicProcedure } from '../trpc'

export const helloRouter = createRouter({
//protect works great
protected: publicProcedure
.input(
z.object({
input: z.string(),
}),
)
.query((ctx) => {
return {
message: `Hello, world from tRPC! ${ctx.input.input}`,
}
}),
//Any other will throw the printscreen waring in the client
greeting: publicProcedure.query(() => 'hello tRPC v10!'),
})
import { z } from 'zod'

import { createRouter, publicProcedure } from '../trpc'

export const helloRouter = createRouter({
//protect works great
protected: publicProcedure
.input(
z.object({
input: z.string(),
}),
)
.query((ctx) => {
return {
message: `Hello, world from tRPC! ${ctx.input.input}`,
}
}),
//Any other will throw the printscreen waring in the client
greeting: publicProcedure.query(() => 'hello tRPC v10!'),
})
even if I rename "protected" it'll happen so I believe I'm missing some hard coded definition or something. This is my config file:
export const createTRPCContext = async (opts: { headers: Headers }) => {
const { session, user } = await auth()

return {
db,
session,
user,
...opts,
}
}

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError:
error.cause instanceof ZodError ? error.cause.flatten() : null,
},
}
},
})
export const createCallerFactory = t.createCallerFactory

export const createRouter = t.router

export const publicProcedure = t.procedure

export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session || !ctx.user) {
throw new TRPCError({ code: 'UNAUTHORIZED' })
}

return next({
ctx: {
session: { ...ctx.session },
user: { ...ctx.user },
},
})
})
export const createTRPCContext = async (opts: { headers: Headers }) => {
const { session, user } = await auth()

return {
db,
session,
user,
...opts,
}
}

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError:
error.cause instanceof ZodError ? error.cause.flatten() : null,
},
}
},
})
export const createCallerFactory = t.createCallerFactory

export const createRouter = t.router

export const publicProcedure = t.procedure

export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session || !ctx.user) {
throw new TRPCError({ code: 'UNAUTHORIZED' })
}

return next({
ctx: {
session: { ...ctx.session },
user: { ...ctx.user },
},
})
})
thanks in advance for your time reading it!
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?