Skip to content

feat: add Elysia adapter#46

Open
wobsoriano wants to merge 6 commits intosupabase:mainfrom
wobsoriano:rob/elysia-adapter
Open

feat: add Elysia adapter#46
wobsoriano wants to merge 6 commits intosupabase:mainfrom
wobsoriano:rob/elysia-adapter

Conversation

@wobsoriano
Copy link
Copy Markdown
Contributor

@wobsoriano wobsoriano commented May 5, 2026

What kind of change does this PR introduce?

Feature

What is the current behavior?

@supabase/server ships framework adapters for Hono and H3 / Nuxt, but not for Elysia. Users building APIs with Elysia have to wire up Supabase auth manually with the core primitives.

What is the new behavior?

Adds @supabase/server/adapters/elysia, a first-class plugin adapter for Elysia. Elysia has been gaining significant traction in the TypeScript ecosystem, particularly in the Bun community, for its end-to-end type safety and expressive plugin API.

Usage with a plain Elysia app:

import { Elysia } from 'elysia'
import { withSupabase } from '@supabase/server/adapters/elysia'

const app = new Elysia()
  .use(withSupabase({ auth: 'user' }))
  .get('/games', async ({ supabaseContext }) => {
    const { data: myGames } = await supabaseContext.supabase
      .from('favorite_games')
      .select()

    return myGames
  })

app.listen(3000)

Per-route auth using scoped groups:

const app = new Elysia()
  .get('/health', () => ({ status: 'ok' }))
  .group('/api', (app) =>
    app
      .use(withSupabase({ auth: 'user' }))
      .get('/profile', ({ supabaseContext }) => supabaseContext.userClaims),
  )

Custom error handling via Elysia's onError:

const app = new Elysia()
  .use(withSupabase({ auth: 'user' }))
  .onError(({ code, error, status }) => {
    if (code !== 'SupabaseAuthError') return

    const cause = error.cause as { code?: string; status?: number } | undefined

    return status((cause?.status as 401) ?? 500, {
      error: error.message,
      code: cause?.code,
    })
  })

Additional context

  • Uses Elysia's .resolve() hook with .as('scoped') so the context propagates to parent app routes.
  • Auth failures throw a registered SupabaseAuthError, which integrates with Elysia's standard onError flow and preserves the original AuthError on error.cause.Consumers discriminate on code === 'SupabaseAuthError' in onError without needing to import the class.
  • Test coverage mirrors the Hono and H3 adapter tests.
  • Docs and package metadata were updated to include Elysia in the adapter tables, exports, and generated API docs.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@supabase/server@46

commit: 2fbc72f

@wobsoriano wobsoriano marked this pull request as ready for review May 5, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant