Trpc not accessing jwt

The NextJS app compiled as production works on my local but on Vercel I’m facing the authentication issue in trcp.

The trpc endpoints are defined with:

export const protectedProcedure = procedure.use(async (opts) => {
  const { req } = opts.ctx;
  const nreq = req!;
  const jwt = await handler(nreq);

  if (!jwt || !jwt.id) {
    console.log("jwt>>>>>>>>", jwt);
    throw new Error("User not authenticated B");
  }

  // Extend the context to include `userId`
  return opts.next({
    ctx: {
      ...opts.ctx,
      userId: jwt.id,
    } as Context,
  });
  
});

On Vercel the trpc throw: throw new Error(“User not authenticated B”);

I’ve checked the environment varaibles and they all all in order. I can even authenticate in my app on Vercel and see my loggedin profile on the main page (which is not using the trcp) but as soon as I navigate to the page which uses trcp I’m experiencing the issue.

I’ve setup up local https reverse proxy and I’m observing this issue on the local as well.

Hey, @lambder!

It seems like this is more of a code issue than Vercel (as far as I understand)

Could you provide a minimal reproducible example for us?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.