Skip to content

feat: Adapter for firebase callable functions #6388

Open

Description

@glorat

Describe the feature you'd like to request

An adapter such that web clients can call a type safe client API routed to firebase callable functions (a single function instance) that is then implemented in the backend in the usual way but wrapping the callable functions specification (e.g. use firebase's context for context etc.)

Describe the solution you'd like to see

Actually, I don't expect a solution from the core team - I'm offering to write it myself

Describe alternate solutions

Currently rolling my own RPC framework around zod - but why maintain that wheel when trpc exists

Additional information

Per above, I'm up for doing the implementation if noone else has done anything. Purpose of me filing this ticket is to ask what consideration has been given to this before and whether I'm likely to run into any gotchas if I go down this road or it should be as simple as another adapter. Also, pointing me to the most relevant existing adapter would be helpful to me.

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

Activity

  1. glorat commented on Jan 19, 2025

    @glorat
    Author

    I had a start but I think I have to suspend effort for now as the way firebase does monorepo doesn't cleanly fit with trpc. (The client and server have their own package.json and tsconfig.json. Server must target cjs, client on ESM. It's a bit too much to untangle at this time).

    In case anyone else tries, what I did succeed in doing is setting up the backend to be based on trpc and handle as callable functions. My existing front end code was able to call it just fine. Here's a code snippet

    export const trpcFunction = onCall(
      {
        /* your options here */
      },
      async (req) => {
        const data = req.data
        const fn: string = data.function // by convention
        const procedures = appRouter._def.procedures as unknown as RouterRecord
    
        const cb = procedures[fn] as AnyProcedure
        if (!cb)
          throw new functions.https.HttpsError(
            'invalid-argument',
            `Function name "${fn}" must be a valid string in data.function`
          )
        // TODO: catch trpc errors and rethrow as HttpsError
        return await cb({
          path: fn,
          getRawInput: async () => req,
          ctx: req,
          type: cb._def.type, // actually must be POST/mutation by callable convention
          signal: undefined,
        })
      }
    )
  2. glorat commented on Feb 8, 2025

    @glorat
    Author

    I'm making decent progress - my firebase callables backend is now entirely on trpc which has the added bonus that all the tests get the typesafe proxies to use and my procedures are now portable if I need to switch away from callable functions. It will be a slow process to get the front end adapters working too to bring it all together.

    If anyone else has interest in the effort, ping me and I'll share everything useful.

  3. saenzramiro commented on Sep 9, 2025

    @saenzramiro

    Any progress/news on this? It will be great to have this.

  4. KATT commented on Nov 2, 2026

    @KATT
    Member

    🤖 v12 has a Firebase callable recipe (experimental): https://v12.trpc.io/v12/docs/adapters/firebase. v12 isn't released yet and there's no ETA.

  5. added
    next-major/definite
    next-major/maybe
    and removed
    next-major/definite
    on Nov 2, 2026
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

    next-major/maybe

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions