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.Documentation Index
Fetch the complete documentation index at: https://docs.microapp.io/llms.txt
Use this file to discover all available pages before exploring further.
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: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
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
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
useSupabasehook 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
subclaim as the user ID
Token Structure
Microapp JWT tokens include these important claims:subis used by Supabase asauth.uid()and contains the user IDmetadata.usercontains user information like email and profile picturemetadata.appcontains the microapp detailsaudandroleare set to “authenticated” for Supabase compatibilityexpis the expiration time (in seconds since epoch)iatis 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
useSupabasehook 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