Skip to main content
Home

Built and signed on GitHub Actions

It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
88%
Published
2 months ago (1.0.0)

supabase-edge-function-helpers

Elegant helpers for Supabase Edge Functions with Deno, including CORS handling and typed Supabase client presets.


Installation

denopm add @huy9k/supabase-edge-function-helpers
# or
npx jsr add @huy9k/supabase-edge-function-helpers

Usage

CORS Handling

import { corsHeaders, handleCors } from "jsr:@huy9k/supabase-edge-function-helpers";

Deno.serve(async (req) => {
  // Handle CORS preflight
  const cors = handleCors(req);
  if (cors) return cors;

  // ...your logic...
  return new Response("Hello", { headers: corsHeaders });
});

Supabase Client Presets

import { clientPresets } from "jsr:@huy9k/supabase-edge-function-helpers";

// Admin client (service role)
const admin = clientPresets.admin();

// User client (JWT)
const user = clientPresets.user("<jwt>");

// Anonymous client
const anon = clientPresets.anon();

API Reference

corsHeaders: Record<string, string>

CORS headers for Supabase Edge Functions. Use in all responses.

handleCors(req: Request): Response | null

Returns a 204 CORS preflight response if req.method === "OPTIONS", otherwise null.

clientPresets

  • admin(): SupabaseClient — Uses SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY from env.
  • user(token: string): SupabaseClient — Uses SUPABASE_URL, SUPABASE_ANON_KEY and sets Authorization: Bearer <token>.
  • anon(): SupabaseClient — Uses SUPABASE_URL and SUPABASE_ANON_KEY.

Environment Variables

  • SUPABASE_URL
  • SUPABASE_SERVICE_ROLE_KEY
  • SUPABASE_ANON_KEY

These must be set in your Edge Function environment.


Compatibility

  • Designed for Supabase Edge Functions and Deno Deploy.
  • Requires Deno runtime and access to Deno.env.
  • All imports are version-pinned for JSR compatibility.

License

MIT

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@huy9k/supabase-edge-function-helpers

Import symbol

import * as supabase_edge_function_helpers from "@huy9k/supabase-edge-function-helpers";
or

Import directly with a jsr specifier

import * as supabase_edge_function_helpers from "jsr:@huy9k/supabase-edge-function-helpers";

Add Package

pnpm i jsr:@huy9k/supabase-edge-function-helpers
or (using pnpm 10.8 or older)
pnpm dlx jsr add @huy9k/supabase-edge-function-helpers

Import symbol

import * as supabase_edge_function_helpers from "@huy9k/supabase-edge-function-helpers";

Add Package

yarn add jsr:@huy9k/supabase-edge-function-helpers
or (using Yarn 4.8 or older)
yarn dlx jsr add @huy9k/supabase-edge-function-helpers

Import symbol

import * as supabase_edge_function_helpers from "@huy9k/supabase-edge-function-helpers";

Add Package

vlt install jsr:@huy9k/supabase-edge-function-helpers

Import symbol

import * as supabase_edge_function_helpers from "@huy9k/supabase-edge-function-helpers";

Add Package

npx jsr add @huy9k/supabase-edge-function-helpers

Import symbol

import * as supabase_edge_function_helpers from "@huy9k/supabase-edge-function-helpers";

Add Package

bunx jsr add @huy9k/supabase-edge-function-helpers

Import symbol

import * as supabase_edge_function_helpers from "@huy9k/supabase-edge-function-helpers";