MFS401 : Table of Contents

Chapter 6

Lesson 3

Pushing the Boundaries: A Deep Dive into Advanced Edge Functions Concept

Foundational

Using Supabase-js in Edge Function

Edge Function as Database Webhooks

Advanced

Using Edge Function with User's Auth Context to follow RLS policies

CI/CD on Edge Function with GitHub Actions

CORS support in Edge Functions

Building a full-fledged GraphQL API on Edge Functions

Quiz it to win it

Take the quiz

3 Questions
12 XP

In the previous lesson, we wrote our first edge function and got familiar with the basic structure of an edge function. In this lesson, we will write edge functions for some complex use cases. We will start with a basic example and gradually move to complex ones.

Using Supabase client with authentication in Edge Function


In our first example, we will use supabase-js within the edge function to get data from our RLS enabled table. We assume that we have a users table in our public schema containing info of each user and has an RLS policy allowing users to access only their data.

We will write an edge function, which, if invoked by an authenticated user, will send that particular user’s info from the users table.

We first import the modules we will need. Supabase recommends using esm.sh for importing Node.js modules that are published to npm. To do so, we can simply put https://esm.sh/ in front of the package name. Here, we are importing the supabase module using esm.

In our handler, we initialise the supabase client using the createClient method. Supabase URL and the anon key are accessible by default in the env for edge function, and we can access them using Deno’s built-in Deno.env.get method.

Get started for free today!

No commitments. No contracts. Enjoy all features for a day — join in just three clicks!

No credit card required.

Quiz it to win it

Complete this quiz successfully to proceed to the next lesson and win upto 12XP.

Start quiz for this lesson

Completing this quiz will get you

+12 Experience Points

+5% course progress