Supabase for databases
Using Supabase with Bolt to add a database, authentication, or edge functions to your app.
If you’re new to setting up databases and authentication, check out the New to … sections: New to databases, New to authentication, and New to edge functions.
Overview
Bolt by default connects to Supabase for database service, authentication method, and edge functions.
Supabase provides:
- A hosted SQL database, which you can connect your application to. You don’t need to worry about managing your database.
- Authentication services, for adding user login and user management to your application.
- Edge functions: Bolt uses these if your application needs to include an API. They’re also used for communicating with other applications, such as Stripe for payment handling.
Explore Supabase’s website and documentation for full details of Supabase’s features.
Connect Bolt to Supabase
- Open the menu by hovering over the left side of the screen or clicking Open sidebar
.
- Go to Settings > Applications.
- Next to Supabase, click Connect.
- Log in with your Supabase credentials. Follow the steps to authorize Bolt.
Use Supabase in your Bolt project
With your Bolt project open:
- Click Integrations > Supabase.
- Choose an existing Supabase project to connect to, or create a new one.
- Bolt may need to make changes to the database. If so, Bolt tells you in the chat. Click Apply changes to proceed.
Disconnect Supabase
- On the Bolt homepage, hover over the left-hand side of the page to open the menu.
- Go to Settings > Applications.
- Next to Supabase, click Disconnect.
- In Supabase, remove Bolt from your authorized applications:
- On the Supabase dashboard, make sure you’re in the organization that you connected to Bolt.
- In the left menu, click Organization settings.
- Go to the OAuth Apps tab.
- Next to Bolt, click Delete.
Using authentication
If you tell Bolt to add authentication with Supabase, users will be able to sign up for your application and log in using Supabase’s user management service.
Make sure you’ve connected your Supabase account as described above. Prompt Bolt to add authentication with Supabase, including adding a signup and login screen to you application.
Once everything is working in your application, you can confirm users are being added correctly in Supabase:
- Go through the signup process in your application.
- Supabase should send you an email to confirm your email address.
- In Supabase, open your project.
- In the left hand menu, select Authentication.
- Check the Users list to confirm that the user you just created was added there.
Using edge functions
Edge functions in Bolt rely on Supabase. Before you begin, make sure you have connected your Supabase account as described above. To get started, prompt Bolt to create the edge function you are interested in. For example: Create an edge function to handle a conversation with an AI Bot (OpenAI)
. From here, Bolt generates the edge function.
Edge functions can be complex, as they connect up services and involve authentication steps. For help with common errors, check out Integrations issues | Supabase edge functions.
New to databases
A database stores and organizes all the information your app needs to remember. Databases store things like user information, settings, preferences, user activity (such as purchase history), and so on.
Traditionally, setting up databases is a complex task: you need to manage the database server, set up backups, keep it secure, and handle scaling as the amount of data grows.
Supabase simplifies this by handling a lot of the management tasks for you, including: instant automatic setup, server management, automatic backups, and automatic scaling. Supabase also provides a visual interface for you to explore and configure your database.
New to authentication
Allowing users to log in to your application, and protecting their data, is a common requirement. This topic can get very complicated: there are many types of authentication available, and a lot of security concerns to think about.
Supabase makes a lot of this easier: you can set up a basic signup and login process by connecting your Supabase account and prompting Bolt to do the setup. You can then add other types of authentication, such as social login.
When thinking about access to your application, it’s helpful to be aware of two key concepts:
- Authentication: this confirms that the user is who they say they are.
- Authorization: this checks if the user has permission to access a particular piece of data.
Supabase can help with both: their authentication service handles login (authentication), and features like row level security allow you to control what data your users can access and what they can change.
It’s a good idea to explore Supabase’s documentation, and read up on best practices, to make sure you’re protecting user data.
New to edge functions
Unlike databases and authentication, you may not have even heard the term “edge functions” before.
In simplified terms: edge functions are small pieces of code that run automatically when something happens in your application. They’re called “edge” functions because they run on servers positioned at the “edge” of the internet, meaning they’re geographically close to wherever your users are located.
When you build an application in Bolt, most of it runs in the user’s web browser. But sometimes you need things to happen behind the scenes that the user can’t see or control. That’s where edge functions come in.
Example use cases for edge functions:
- Sending emails.
- Processing payments.
- Connecting to other services.
Edge functions have a couple of key benefits:
- Speed: because they run close to your users, they respond quickly.
- Security: sensitive operations should always be done in edge functions, not in the browser, to keep data secure and avoid security risks.