Documentation Index
Fetch the complete documentation index at: https://tech.illasoft.com/llms.txt
Use this file to discover all available pages before exploring further.
使用 Supabase Edge Functions 处理数据库事件触发的任务。
signup-function
监听用户注册事件,发送埋点到 PostHog。
触发方式
通过 Supabase Database Webhook 触发:
| 配置 | 值 |
|---|
| 表 | auth.users |
| 事件 | INSERT |
| 运行时 | Deno |
代码结构
// supabase/functions/signup-function/index.ts
interface WebhookPayload {
type: "INSERT" | "UPDATE" | "DELETE";
table: string;
record: {
id: string;
email?: string;
created_at?: string;
};
schema: string;
old_record: null | Record<string, any>;
}
Deno.serve(async (req) => {
const payload: WebhookPayload = await req.json();
// 只处理 users 表的 INSERT 事件
if (payload.type !== "INSERT" || payload.table !== "users") {
return new Response(JSON.stringify({ message: "Event ignored" }));
}
// 发送 kira_signup 事件到 PostHog
await sendToPostHog(userId, userEmail, userName);
});
环境变量
| 变量 | 说明 |
|---|
POSTHOG_API_KEY | PostHog 项目 API Key |
本地开发
supabase functions serve signup-function --env-file ./supabase/.env.local
supabase functions deploy signup-function
Database Webhook 配置
在 Supabase Dashboard 中配置:
- 进入 Database → Webhooks
- 创建新 Webhook:
- Table:
auth.users
- Events:
INSERT
- URL:
https://<project>.supabase.co/functions/v1/signup-function
- Headers: 添加
Authorization 头,值为 service role key