Develop with Supabase
This document will guide you through the initialization and usage of Supabase in your mono-repo, which includes Expo, Next.js, and common components. Your Supabase local setup already includes edge functions, Google Auth, email auth, tables, and storage buckets.
Architecture
Please refer here for the architecture.
Supabase Initialization
Since your local Supabase setup is already configured, follow these steps to initialize and use Supabase in your projects.
-
Start Docker: Make sure docker is running before you start the supabase setup.
-
Starting Supabase: Start the Supabase local development environment by running the pre-written scripts in root
package.json
: -
Environment Variables: The previous command will show you a set of sercet keys, save them for future references. Update the relevant keys in all the env files provided. e.g.
You have successfully initialized Supabase. You can now leverage Supabase’s powerful features such as edge functions, authentication, tables, and storage buckets. If you encounter any issues, refer to the Supabase documentation for further assistance.
Migrations
The migrations are setup that gives the supabase db, some table, their RLS security policy rules. It includes :
- Tables and storage buckets for database which are linked via primary keys.
- Row level security policies implemented in both tables and storage.
- Triggers on events like
create_new_user
.
Edge Functions
We have three edge functions in this project :
-
payment-data-native : This webhook is used to initialising payment with stripe for native devices.
-
payment-data-web : This webhook is used to initialising payment with stripe for the web.
-
stripe-webhook : This webhook is never triggered directly or called by the client, instead it is only called when any relevant event in stripe is triggered.
Setup ENV
-
The environmental varianbles used by the edge functions are different from what is provided to the supabase root folder env.
-
The location of these env is
apps/supabase/supabase/functions/stripe-webhook/.env.example
-
Enter the secret keys required.
There are 2 methods to using the edge functions :
-
invoking directly :
supabase.functions.invoke
can be used to directly call the edge function from the client app. It returns a promise which is then resolved. -
serving the edge function : you can serve the edge function and it will work as an api call.
Note:
--no-verify-jwt
flag is required to avoid cors-error i.e, if your client is web based.e.g.
or you can use the script already created and just run