tRPCttRPC
Powered by
kazamyrK
tRPC•3y ago•
2 replies
kazamyr

tRPC mutate call firing two requests with custom link

Node: 18.16
tRPC: 10.38.0
pnpm

What's wrong with this custom link that's causing it's addition to a tRPC client to make two requests?

/**
 * Checks tRPC errors, if UNAUTHORIZED it notifies the front-end the user's
 * token is no longer valid.
 */
export const unauthorizedLink =
  <TRouter extends AnyRouter>(): TRPCLink<TRouter> =>
  () =>
  ({ op, next }) => {
    const observable = next(op);
    observable.subscribe({
      error: (error) => {
        if (error.shape?.data.httpStatus === StatusCodes.UNAUTHORIZED) {
          useEnduvoToken.getState().clearToken();
        }
      },
    });

    return observable;
  };
/**
 * Checks tRPC errors, if UNAUTHORIZED it notifies the front-end the user's
 * token is no longer valid.
 */
export const unauthorizedLink =
  <TRouter extends AnyRouter>(): TRPCLink<TRouter> =>
  () =>
  ({ op, next }) => {
    const observable = next(op);
    observable.subscribe({
      error: (error) => {
        if (error.shape?.data.httpStatus === StatusCodes.UNAUTHORIZED) {
          useEnduvoToken.getState().clearToken();
        }
      },
    });

    return observable;
  };


There isn't a lot of documentation about custom links.
image.png
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

calling tRPC procedure from custom link
SparkSSpark / ❓-help
2y ago
ECONNREFUSED with TRPC call on Vercel
xdxd#5555 / hanyaXxdxd#5555 / hanya / ❓-help
3y ago
Create user on the function mutate, with TRPC and Payload
jasonnpwJjasonnpw / ❓-help
2y ago