Integrate with Supabase
Securely connect your microapp to Supabase using JWT bridging for authentication and data access.
Integrate your microapp with Supabase by bridging authentication using JWT tokens generated by Microapp. This approach lets you use Microapp for user identity and securely access Supabase data—without using Supabase’s built-in authentication.
Supabase authentication is not compatible with Microapp. Always use the JWT token generated by Microapp to authenticate and check users in Supabase.
Prerequisites
- A Supabase account and project
- Your microapp set up with one of our supported frameworks
1. Set Up Your Supabase Project
- Sign in to Supabase and create a new project.
- Note your project’s URL and anon/public API key from the project settings. You’ll need these to connect your microapp.
2. Install the SDKs
Install both the Microapp SDK and Supabase client:
3. Create a Supabase Hook
Create a React hook that provides a Supabase client authenticated with the current user’s JWT token:
Replace your-supabase-url
and your-anon-key
with your actual Supabase project values.
4. Use Supabase in Your Components
Now you can use both Microapp and Supabase authentication in your components:
5. Configure JWT Authentication
To let Supabase validate Microapp’s JWT tokens, both systems must use the same JWT secret:
- Copy the Microapp JWT Secret
- Go to Microapp Creator Dashboard → Settings → JWT Secret and copy the value
- Or generate a new secret if needed
- Set the Same Secret in Supabase
- Go to Supabase Dashboard → Project Settings → Auth → JWT Settings
- Paste the same secret under
JWT Secret
Both Microapp and Supabase must use the exact same JWT secret so that tokens can be verified.
6. Set Up Row Level Security (RLS)
Enable secure access to user-owned data with RLS policies:
7. Deploy and Test
- Test authentication and database queries in your local environment
- Ensure your environment variables are set in your deployment platform
- Deploy your microapp as usual
For advanced features like real-time subscriptions, storage, and edge functions, see the Supabase documentation.
Understanding JWT Authentication Flow
Here’s how authentication works between Microapp and Supabase:
Data Flow Overview
- User logs in via Microapp and receives a JWT token
- Your React app gets the token using
useAuth()
- The
useSupabase
hook creates a client with the user’s token - All Supabase queries are authenticated with that token
- Supabase enforces Row Level Security using the token’s
sub
claim as the user ID
Token Structure
Microapp JWT tokens include these important claims:
sub
is used by Supabase asauth.uid()
and contains the user IDmetadata.user
contains user information like email and profile picturemetadata.app
contains the microapp detailsaud
androle
are set to “authenticated” for Supabase compatibilityexp
is the expiration time (in seconds since epoch)iat
is the issued-at time
Token Management
- Default TTL: Tokens expire after 60 minutes by default
- Custom TTL: You can modify the token expiration time in the Microapp Creator Dashboard
- Token Refresh: To get a new token, call
getUserJwtToken()
method or refresh the page - Automatic Handling: The
useSupabase
hook automatically uses the latest token fromuseAuth()
Best Practices
- JWT Bridging: Microapp handles authentication and provides a JWT. You pass this token to Supabase for secure data access
- Token Expiry: If Supabase returns authentication errors, the token may have expired - simply refresh or call
getUserJwtToken()
- Security: Never share JWT secrets publicly. Use environment variables for all secrets and keys
Next Steps
- Explore Supabase features: Auth, Database, Storage
- Integrate with Microapp’s Identity and Monetization systems
- Distribute your microapp on the Microapp marketplace