H
Hono7mo ago
Chicha

how i connect my hono application with supabase project

how i connect my hono application with supabase project
4 Replies
Nico
Nico7mo ago
import { Hono } from 'hono';
import { createClient } from '@supabase/supabase-js';

app.use(async (c, next) => {
const supabase = createClient(c.env.SUPABASE_URL, c.env.SUPABASE_KEY);
c.set('db', supabase);
await next();
});
import { Hono } from 'hono';
import { createClient } from '@supabase/supabase-js';

app.use(async (c, next) => {
const supabase = createClient(c.env.SUPABASE_URL, c.env.SUPABASE_KEY);
c.set('db', supabase);
await next();
});
This would be specific to Cloudflare Workers since you can only access environment vars inside the content.
Nico
Nico7mo ago
Here is for reference how to use get/set https://hono.dev/api/context#set-get
Context - Hono
Ultrafast web framework for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Nico
Nico7mo ago
And how to add it to the types globally https://hono.dev/api/context#contextvariablemap
Context - Hono
Ultrafast web framework for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Nico
Nico7mo ago
Inside your route you can call c.get('DB') to call your database
Want results from more Discord servers?
Add your server