Tulip Logo IconTulip
Router

Context

Define app-local ORPC context with database, auth, headers, and request-specific values.

Router context is app-owned.

Use it to pass shared request services such as database, auth, headers, session data, and feature-specific service clients into ORPC procedures.

Example

import { os } from "@orpc/server";
import { auth } from "../auth/init";
import { db } from "../db/init";

export type RPCContext = {
  db: typeof db;
  auth: typeof auth;
  headers: Headers;
};

export const rpc = os.$context<RPCContext>();

export function createContext<TExtendedContext>(context: TExtendedContext & { headers: Headers }) {
  return { db, auth, ...context } as RPCContext & TExtendedContext;
}

Continue reading

On this page