Connecting Supabase
This guide explains how to integrate Supabase in the Apps in Toss (mini-app) WebView environment. The Supabase JS client works regardless of framework. The code examples are Vite (React + TypeScript) based.
Overview
Supabase is an open-source backend service that provides authentication, databases (PostgreSQL), file storage, real-time subscriptions, and more. You can use it the same way in the Apps in Toss WebView environment, but security settings and environment variable managementare important.
1. Getting started
Supabase account (supabase.com)
a project made with Vite (React + TypeScript)
Node.js, npm (or yarn, pnpm)
2. Create a Supabase project
In the Supabase dashboard, New projectclick to create a new project.
Set the project name, database password, and region, then complete the creation.
Once the project is ready, you can check the following information in the dashboard.
Project URL : https://<project-id>.supabase.co
Publishable key : sb_publishable_xxxxxxxxxxxx3. Set environment variables
For security, we recommend managing your Supabase connection details as environment variables. In the project root, .env create a file and write it like this.
4. Install and initialize Supabase
src/supabase/client.ts create a file and initialize the Supabase client like this.
5. Database usage example
Once the Supabase client is initialized, you can read or write data inside React components. Below is the simplest example of reading and saving a single row in App.tsx.
In the Supabase dashboard's Table Editorcreate a users table and add id(int8, primary key) and name(text) columns.
How it works
Read data (
.select())usersfetches a rowidwhere the id is 1 from the table, once.If the row exists,
namethe value is displayed on screen.
Write data (
.upsert())the entered name to
usersthe table.If the row does not exist, it is created; if it does, it is overwritten.
6. Security checklist
Manage sensitive information as environment variables
Do not write Supabase URL, publishable key, etc. directly in code; manage them
.envwith
Do not upload environment files to Git, etc.
.envBe sure to add the.gitignorefile.If a key is exposed, immediately reissue the key in the Supabase dashboard.
Be sure to set Row Level Security (RLS)
All tables in Supabase have RLS disabled by default.
When RLS is off, anyone with only the publishable key can access the entire table.
Before deployment, be sure to enable RLS and set policies so only authenticated users can access it.
Supabase dashboard Table Editor → select table → RLS You can configure it in the tab.
Check origin restrictions
In the Supabase dashboard's Authentication → URL Configurationset the allowed domains here.
Allowing only the mini-app (WebView) domain can prevent unauthorized access.