
Plasmic
Overview
By integrating Supabase with Plasmic — a visual builder for the web — you can create data-backed applications without writing code. Although many users leverage Plasmic for rapid landing page development, this tutorial demonstrates its power as a general-purpose visual builder for React, enabling the creation of fully featured read-write applications.
Documentation
In this guide, we’ll walk you through building a crowd-sourced Pokémon Pokédex by connecting Supabase, an open-source Firebase alternative, with Plasmic, a visual web builder.
Live demo (signing up is quick):
https://plasmic-supabase-demo.vercel.app
Repository:
https://github.com/plasmicapp/plasmic/tree/master/examples/supabase-demo
Plasmic project:
https://studio.plasmic.app/projects/66RKaSPCwKxYjCfXWHCxn6
At a high level:
- Supabase serves as the backend (powered by Postgres) for storing Pokémon data and managing authentication. Our code base includes React components for querying the database, displaying data, and handling user sessions.
- Plasmic is used to build the application’s pages and design its visual layout. We import our Supabase components into Plasmic Studio, where they can be visually arranged and configured (for instance, to display data).
- Plasmic-designed pages are rendered back into the Next.js application.
Step 1: Set up your Backend on Supabase
- On the Supabase dashboard, click New project and give your project a name.
By default, Supabase configures email-based signups, storing users in the users
table.
- Navigate to the Table Editor in the left sidebar. Here, create a New table to store your Pokémon entries. Ensure you are in the
schema public
view and create a table calledentries
with six columns:id
: A unique identifier for the entry, automatically generated as the primary column.user_id
: Create a relation to the user table by clicking the link 🔗 icon next to the column name and selecting theid
column from theuser
table.name
,description
,imageUrl
: These columns store the Pokémon’s name, description, and image URL respectively.inserted_at
: Automatically populated with the timestamp when the row is first inserted.
Note: In this tutorial, we’ve turned off Row Level Security (RLS). In a production environment, you should create policies that restrict who can create, edit, and delete posts. With RLS off, any user can modify the database without restrictions.
For convenience, you can import the following CSV file into Supabase to pre-populate your database. To import, select Import data via spreadsheet in the new table dialog box (this does not work on existing tables):
You’ll also need to create a function in your database to fetch the schema. This function will retrieve the Supabase database schema to display the table and column names in Plasmic Studio.
To do this, navigate to Database → Functions and click Add a new function.
Use get_table_info
as the function name and leave the schema as public. In the Return type field, select JSON
.
Paste the following function definition:
Since we’ve disabled RLS for now, ensure that your function is executable by the anonymous user. To do this, navigate to the SQL Editor in the sidebar and run the following query:
Important! Make sure to revert this step when you add RLS to your table later.
Step 2: Set up your codebase
We have a working code example available here. This starter project includes all the code components you need to begin querying Supabase through Plasmic Studio.
Code components are React components defined in your code base that we import into Plasmic Studio. Your project is configured to look for these at
http://localhost:3000/plasmic-host
. You can use and style these components in your design. Seesupabase-demo/plasmic-init.ts
to understand how they are registered with Plasmic.
First, clone the repo to your development machine:
Copy .env.example
to .env
to store your environment variables for the local development server. Then, add your Supabase project’s URL and public key (found in the API tab on the left pane of your Supabase dashboard).
Install the dependencies and fetch the Supabase schema by running:
Now, start the development server (it listens on http://localhost:3000):
Step 3: Explore the existing application
Open http://localhost:3000 in your web browser. The project is already set up for user sign-ups and logins and includes an admin interface for adding and editing Pokémon in the database. Feel free to sign up with your email address and add Pokémon entries. Note that Supabase requires email verification before you can log in.
If you pre-populated the database in Step 1, you should see the following homepage after logging in. Otherwise, you can manually add Pokémon via the UI.
Step 4: Clone the Plasmic project
Now, let’s make some enhancements! The code base is initially set up with a read-only copy of the Plasmic project. Let’s create an editable copy first.
Open the default starter Plasmic project here:
https://studio.plasmic.app/projects/66RKaSPCwKxYjCfXWHCxn6
To create an editable copy, click the Copy Project button in the blue bar. This will clone the project and redirect you to your copy.
Step 4a: Configure your code base to use the new Plasmic project
Take note of the project ID
and API token
. You can find the project ID in the URL:
https://studio.plasmic.app/projects/PROJECTID
.
The API token is available by clicking the Code button in the top bar.
Return to .env
and update the corresponding project ID and token fields.
Step 4b: Configure your Plasmic project app host
To ensure Plasmic looks for your code components on your development server, update your project’s app host to http://localhost:3000/plasmic-host.
Note: Keep your development server running at http://localhost:3000 for the project to load.
After restarting both the dev server and Plasmic Studio, you should be able to edit both the Studio and your codebase.
Step 4: Deployment (optional)
You can host your application using Vercel, Netlify, AWS, or any other provider you prefer.
In this section, we will cover deployment using Vercel:
- First, create a GitHub repository for your project.
- Next, log into vercel.app and add a new project.
- Point to the repository you created in the first step.
- Go to the project settings.
- Set the Build & Development settings to the following:
- Set the Node.js version to 20.x.
- Go to the Environment Variables tab and copy the contents of your .env file.
- Trigger a deployment of your project.
- (optional) go back to step 4b, and point to your /plasmic-host page using your newly created domain. (for example, https://plasmic-supabase-demo.vercel.app/plasmic-host)
You can also refer to this video to see how another project is configured on Vercel and Netlify.
If you plan to use Plasmic hosting, you will need to disable the Supabase email verification feature in Authentication → Providers → Email. Supabase requires you to set up a Next.js API route, which we don’t support yet.
Step 5: Create a new page – Look up Pokémon by name
Let’s create a lookup page for our Pokédex using the code components from the code base.
- Create a new page called
Guess
and set its path to/guess
. - Add a NavBar and any additional elements to enhance the layout (we used two vertical containers for background and centering).
- Insert a
SupabaseDataProvider
by opening the AddDrawer (click the blue + button).
For source, see
components/CodeComponents/DatabaseComponents/SupabaseDataProvider
.
Above the SupabaseDataProvider
, add a text input element and a heading. Change the text input’s placeholder to Type your guess
. Your layout should resemble the following:
Next, configure the props for the SupabaseDataProvider
in the right-hand panel:
- Table: Set this to the table you created in Supabase.
- Columns: Provide a comma-separated list of the columns you want to select from the table.
- Filters: Define which data to fetch (similar to a WHERE clause).
- Single: Specify whether to fetch a single record or multiple records.
Additionally, we set a visibility condition so that data is fetched only when the input contains more than three characters.
This is how the filter parameter should appear, with the operation set to eq (meaning it will fetch records where the property equals a specific value).
The SupabaseDataProvider
passes down the fetched data, leaving it up to you to decide how to use it.
Next, add a Post
component (used on the homepage) to display the Pokémon.
If no matching Pokémon exists in the database, configure a nearby text node to inform the user. Control its visibility based on the data from the SupabaseDataProvider
—this is how you can access that data in the Studio:
Finally, add your new page as a link in the NavBar component. Try this as an exercise 🙂
Step 6: Check your dev server
If your development server has been running all along, you’ll notice that the site automatically fetches and rebuilds as you make changes in Plasmic Studio. To restart the dev server, run:
Then, view the results at http://localhost:3000/guess
How does this all work under the hood?
All the code components are defined in your codebase, and you’re free to enhance them to support more powerful querying capabilities in Plasmic Studio.
Email Verification API Route
To sign up, users must verify their email address. After signing up, they receive an email with a verification link. Clicking the link directs them to the API route at /pages/api/auth/confirm.ts
, which confirms the OTP code and redirects them to the homepage.
Learn more here: https://supabase.com/docs/guides/auth/server-side/nextjs?queryGroups=router&router=pages
SupabaseDataProvider
This simple component executes queries and populates the application's data. If your data is mostly static, consider using usePlasmicQueryData
instead of the mutable version.
How it is registered:
The shared props for this registration are defined below. We use the dbSchema
variable from an auto-generated file that fetches the Supabase schema. This file refreshes during yarn build
or when you run yarn
, allowing the Studio to display current tables and columns without hardcoding them.
SupabaseForm
This component performs database mutations (such as delete, update, or insert operations). It wraps form elements and calls an action upon submission. In most cases, a submit button triggers the form, and the onSuccess
hook is useful for redirecting the user or refreshing page data.
How it is registered:
SupabaseUserSession
This component provides global user data across the application and is registered as a GlobalContext. If you’d prefer not to log in every time to see content from a specific user’s perspective, you can set a staticToken
in the context settings.
You can find the authentication token from the hosted application by inspecting any network request. The token is in the Authentication header (everything after “Bearer”).
Source code:
How it is registered:
RedirectIf
This component redirects the user based on a condition you specify. In our example, it redirects users from inner pages if they are not logged in.
Source code:
And how it is registered:
Details
Third-party integrations and docs are managed by Supabase partners.