Instant deployment
Deploy Edge Functions in seconds
Global
Deployed to 29 regions worldwide
Typescript ready
TypeScript, WASM, ES Modules
Async triggers
Invoke Edge Functions based on any event in your database
Anatomy of an Edge Function
Asynchronous tasks within minutes using Supabase Functions with simple authenticated access to the rest of the Supabase Ecosystem.
1import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'
2import Stripe from 'https://esm.sh/stripe?target=deno&no-check'
3import { Customer } from 'types'
4
5serve(async (req) => {
6 try {
7 // create a supabase client
8 const supabaseClient = createClient(
9 Deno.env.get('SUPABASE_URL') ?? '',
10 Deno.env.get('SUPABASE_ANON_KEY') ?? ''
11 )
12 // create a stripe client
13 const stripe = Stripe(Deno.env.get('STRIPE_SECRET_KEY'))
14
15 // Get the authorization header from the request.
16 const authHeader = req.headers.get('Authorization').replace("Bearer ","")
17 // Client now respects auth policies for this user
18 supabaseClient.auth.setAuth(authHeader)
19 // set the user profile
20 const user = supabase.auth.user()
21
22 // Retrieve user metadata that only the user is allowed to select
23 const { data, error } = await supabaseClient
24 .from<Customer>('user_profiles')
25 .select('address, tax, billing_email, phone')
26
27 if (error) throw error
28
29 const customer = await stripe.customers.create({
30 description: 'My First Stripe Customer (created by a Supabase edge function)',
31 phone: data.phone,
32 address: data.address,
33 email: user.email,
34 })
35
36 return new Response(JSON.stringify(customer), { status: 200 })
37 } catch (error) {
38 return new Response(JSON.stringify(error), { status: 400 })
39 }
40})
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140