Skip to content

fix(api): authMiddleware context is untyped, so c.get() is never and test:deno:types cannot pass #477

Closed

Description

@thinkclay

Found while fixing #443.

authMiddleware stores supabase, user and friends on a plain untyped Context:

export async function authMiddleware(c: Context, next: Next) { ... }

and no route file parameterizes its app:

const app = new OpenAPIHono();   // no Variables type

So c.get("supabase") infers as never, and every property access on it is a type error. deno check on a single route file reports 14 errors purely from this:

TS2339 [ERROR]: Property 'schema' does not exist on type 'never'.
TS2339 [ERROR]: Property 'id' does not exist on type 'never'.

This is repo-wide across functions/api/routes/, not specific to one file, which means pnpm test:deno:types cannot pass and provides no signal today. In #443 I had to route around it with a local reader helper to avoid adding more of the same errors — that is a workaround, not a fix.

Fix

Declare the middleware's context shape once and use it everywhere:

export type ApiEnv = {
  Variables: {
    supabase: SupabaseClient
    user?: { id: string; email?: string }
    organization?: { id: string }
  }
}

// in each route file
const app = new OpenAPIHono<ApiEnv>()

Then c.get("supabase") is typed, the never errors disappear, and test:deno:types becomes a real gate. Mechanical but touches every route file, so it wants its own PR.

Activity

  1. added
    bug
    agent-ready
    on Jul 30, 2026
  2. added a commit that references this issue on Sep 2, 2026
    87557be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXagent-readybugtype: backend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions