Using Lazy router with $context
#446
Unanswered
ValentinGurkov
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You need to do something like this: os
.$context<{ headers: ReadonlyHeaders }>()
.lazy((async () => {
const { planetRouter } = await import('./routers/planet');
return { default: planetRouter };
}) Maybe this requirement too strict? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I've been following the development of oRPC and I'm still trying to wrap my head around everything it offers.
I've been reading more about lazy routers but it seems to be incompatible with routers that use
$context
. Is this by design and can you help me understand why?If use use the
planet
example and wrap it withos.lazy
it will raise a Typescript error of the like:If I remove
context
from thecreate
route, the error goes awayexport const createPlanet = os - .$context<{ headers: ReadonlyHeaders }>() .use(({ context, next }) => { const user = parseJWT(context.headers.authorization?.split(' ')[1]); if (user) { return next({ context: { user } }); } throw new ORPCError('UNAUTHORIZED'); }) .input(PlanetSchema.omit({ id: true })) .handler(async ({ input, context }) => { // your create code here return { id: 1, name: 'name' }; });
Beta Was this translation helpful? Give feedback.
All reactions