Tutorial: How to connect Supabase database to your Bind AI application
This tutorial will walk you through connecting a Supabase database to your web application, step by step. No technical background required!
What is Supabase?
Supabase is a free database service that lets you store and manage data for your applications without setting up complex servers. Think of it as a digital filing cabinet that your website can read from and write to.
Part 1: Creating Your Supabase Account and Database
Step 1: Sign Up for Supabase
Go to supabase.com
Click "Start your project"
Sign up with your GitHub account or email
Verify your email if required
Step 2: Create a New Project
Once logged in, click "New Project"
Choose your organization (usually your username)
Fill in the project details:
Name: Give your project a memorable name (e.g., "My App Database")
Database Password: Create a strong password and save it somewhere safe
Region: Choose the region closest to your users
Click "Create new project"
Wait 2-3 minutes for the project to be set up
Part 2: Creating Your Database Table
Step 3: Create a Table
In your Supabase dashboard, click "Table Editor" in the left sidebar
Click "Create a new table"
Fill in the table details:
Name: Enter your table name (e.g., "workflows")
Description: Optional description of what this table stores
Click "Save"
Step 4: Add Columns to Your Table
Your table needs columns to store different types of data. Here's how to add them:
Click "New Column" button
For each column, fill in:
Name: The column name (e.g., "name")
Type: Choose the data type:
text
- for names, descriptions, short textbigint
- for numbers (IDs, counts)jsonb
- for complex data structurestimestamp with time zone
- for dates and times
Default Value: Leave blank unless you want a default
Primary Key: Only check this for your ID column
Click "Save"
Example columns for a workflows table:
id
(bigint, Primary Key) - Auto-generated unique identifiercreated_at
(timestamp with time zone) - When the record was createdname
(text) - The workflow nameworkflow_data
(jsonb) - Additional workflow information
Tip: Supabase automatically creates
id
andcreated_at
columns when you create a new table. You just need to add your custom columns!
Part 3: Getting Your Connection Details
Step 5: Find Your Project URL and API Key
In your Supabase dashboard, click "Settings" in the left sidebar
Click "API" under Settings
You'll see two important pieces of information:
Project URL: Looks like
https://abcdefg.supabase.co
Public anon key: A long string starting with
eyJ...
Copy both values - you'll need them in your code
Important: The "anon" key is safe to use in your website code. Never use the "service_role" key in browser code!
Part 4: Disable Row Level Security (For Beginners)
Step 6: Turn Off RLS (Row Level Security)
Row Level Security can prevent your app from saving data. For learning purposes, we'll disable it:
Go to "Authentication" in the left sidebar
Click "Policies"
Find your table (e.g., "workflows")
You'll see a toggle switch for "Enable RLS"
Click to turn it OFF
Confirm when prompted
Note: In production apps, you should enable RLS and create proper policies for security. But for learning, turning it off makes things simpler.
Part 5: Connecting to Your Application
Step 7: Add Supabase to Your Code
Option A: Use AI to Generate the Code (Recommended for Beginners)
Instead of writing code manually, you can ask AI to create it for you. Try out these test prompts to create a simple html file and save data to Supabase :
Prompt 1 - Generate Basic HTML Form:
Create a simple HTML form with a text input for "name" and a submit button. Include the Supabase JavaScript library from CDN and link to a script.js file.
Prompt 2 - Generate Supabase JavaScript Code:
Create JavaScript code that connects to Supabase and saves form data to a table called "workflows" with columns: name (text) and workflow_data (jsonb). Include proper error handling and success messages. Use placeholder values for the Supabase URL and API key that I can replace later.
Option B: Manual Setup (If you prefer to type)
If you want to add Supabase manually, add this line before your closing </body>
tag in your HTML:
Html<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
Step 8: Update Your Supabase Credentials
After the AI generates your code (or if you wrote it manually), you need to replace the placeholder values:
Find your JavaScript file (usually named
script.js
)Look for these lines at the top of the file:
Javascriptconst SUPABASE_URL = 'YOUR-SUPABASE-URL-HERE'; const SUPABASE_ANON_KEY = 'YOUR-SUPABASE-ANON-KEY-HERE';
Replace the placeholder text with your actual values from Step 5:
Replace
'YOUR-SUPABASE-URL-HERE'
with your Project URL (keep the quotes)Replace
'YOUR-SUPABASE-ANON-KEY-HERE'
with your anon key (keep the quotes)
Example of what it should look like:
Javascriptconst SUPABASE_URL = 'https://iloddfdekwsnrxpncwnhlgz.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NidfdfIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imlsb2Rla3dzbnJ4cG5jd25obGd6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDgxNTA4OTcsImV4cCI6MjA2MzcyNjg5N30.7K2yOrXEqZ3e7H1yyVQyc3hSntQNUp7WI3pbLrePqQc';
Step 9: Update Table and Column Names
If your table or column names are different from what the AI generated:
Find the table name in your JavaScript code - look for something like:
Javascript.from('workflows')
Replace
'workflows'
with your actual table nameFind the column names in the insert section - look for something like:
Javascript.insert({ name: name, workflow_data: {} })
Update the column names to match your actual columns
Common Issues and Solutions
Issue 1: "Invalid API key" or Connection Errors
Symptoms: Error messages about invalid keys or failed connections
Solutions:
Double-check your URL and anon key from the Supabase dashboard
Make sure there are no extra spaces or missing characters
Verify you're using the anon key, not the service_role key
Issue 2: Data Not Saving (No Error Messages)
Symptoms: Form submits but nothing appears in your Supabase table
Solutions:
Check Row Level Security: Make sure RLS is disabled (see Step 6)
Verify table and column names: They must match exactly (case-sensitive)
Check browser console: Press F12, look for error messages in the Console tab
Issue 3: "Permission Denied" Errors
Symptoms: Error messages about permissions or access denied
Solutions:
Ensure Row Level Security is disabled
Verify you're using the correct anon key
Check that your table exists and column names are correct
Issue 4: "Column does not exist" Errors
Symptoms: Error messages about missing columns
Solutions:
Check spelling of column names in your code
Verify the columns exist in your Supabase table
Column names are case-sensitive
Issue 5: Wrong Data Types
Symptoms: Errors about data type mismatches
Solutions:
Don't manually set
id
values if using bigint auto-incrementEnsure JSON data is properly formatted for jsonb columns
Match text data to text columns, numbers to numeric columns
Testing Your Connection
Step 10: Verify Everything Works
Test the connection: Try saving a simple record through your form
Check Supabase: Go to your Table Editor and see if the data appears
Check browser console: Press F12 and look for any error messages
Check Supabase logs: In your dashboard, go to "Logs" → "API" to see request logs
Quick Troubleshooting Checklist
When something isn't working, check these in order:
✅ URL and Key: Are they copied correctly from Supabase dashboard?
✅ Table Name: Does it match exactly (case-sensitive)?
✅ Column Names: Do they match your table schema?
✅ RLS: Is Row Level Security disabled?
✅ Browser Console: Any error messages when you submit?
✅ Supabase Logs: Any failed requests in the API logs?
Next Steps
Once you have basic connectivity working:
Learn about Row Level Security: Enable it and create policies for better security
Add more features: Reading data, updating records, deleting records
User authentication: Let users log in and manage their own data
Real-time updates: Subscribe to database changes
Congratulations! You now have a working database connection. Start simple and build up your features gradually.
Last updated