`getSession()` coming back as null in Hono/ORPC middleware

Has anyone used ORPC with Better-Auth? I am trying to do so but sessions are coming back empty. Under the hood it uses Hono:

const app = new Hono();

app.use(
  "/rpc*",
  createMiddleware(handler, {
    prefix: "/rpc",
    context: async (c) => {
      return {
        headers: c.req.raw.headers,
        env: {
          DATABASE_URL: process.env.DATABASE_URL ?? "",
        },
      };
    },
  }),
);


In the middleware, I am trying to call getSession:

export const sessionMiddleware = base.middleware(async ({ context, next }) => {
  const sessionResult = await auth.api.getSession({
    headers: context.headers,
  });
  console.log(`Headers: ${context.headers.get("Authorization")}`); // valid
  const session = sessionResult?.session;
  console.log(`Session: ${session}`); // this is null

I see the header value is valid: Authorization: Bearer {token} but it gets returned as null. Since I am simply saving Hono's req.raw.headers object I feel like it should work; is there some other data that's required to verify a bearer token?
CleanShot_2025-03-29_at_16.52.402x.png
oRPC makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
Was this page helpful?