This document explains how to use Supabase authentication with LangConnect.
-
Supabase project with URL and anon key configured in
.env:SUPABASE_URL=https://your-project.supabase.co SUPABASE_KEY=your-anon-key -
Set
IS_TESTING=falsein your.envfile to enable authentication
-
POST /auth/signup - Create a new user account
{ "email": "user@example.com", "password": "password123" } -
POST /auth/signin - Sign in with existing account
{ "email": "user@example.com", "password": "password123" } -
POST /auth/signout - Sign out (client-side cleanup)
-
POST /auth/refresh - Refresh access token
{ "refresh_token": "your-refresh-token" } -
GET /auth/me - Get current user info (requires authentication)
Successful authentication returns:
{
"access_token": "jwt-token",
"refresh_token": "refresh-token",
"user_id": "user-uuid",
"email": "user@example.com"
}Include the access token in the Authorization header:
Authorization: Bearer your-access-token
The Streamlit app (Main.py) now includes:
- Sign in/Sign up forms
- Automatic token management
- Session persistence
- Sign out functionality
Run the test script:
python test_supabase_auth.pyThis will test:
- User signup
- User signin
- Authenticated API requests
- Getting current user info
- The
SUPABASE_KEYin.envshould be the anon key, not the service role key - Tokens expire after a certain period - use the refresh endpoint to get new tokens
- All API endpoints (except /health and /auth/*) require authentication when
IS_TESTING=false
The Streamlit app supports two methods to persist authentication:
-
Automatic File-Based Storage (Default)
- Authentication tokens are automatically saved to
~/.langconnect_auth_cache - Tokens remain valid for 7 days
- Automatically loads on app restart
- Authentication tokens are automatically saved to
-
Environment Variables (Optional)
- Add these to your
.envfile:
LANGCONNECT_TOKEN=your-access-token LANGCONNECT_EMAIL=your-email@example.com- Useful for development or shared environments
- Add these to your
- The auth cache file is stored in your home directory
- Tokens expire after 7 days for security
- Use environment variables only in secure environments
By default, Supabase requires email confirmation for new signups. When a user signs up:
- They will receive a confirmation email
- They must click the link in the email to confirm their account
- Only then can they sign in
To disable email confirmation (for testing only):
- Go to your Supabase project dashboard
- Navigate to Authentication → Settings
- Under "Email Auth" disable "Confirm email"
When running with Docker Compose, ensure IS_TESTING=false in docker-compose.yml to enable authentication.
- "Authentication endpoints are disabled in testing mode" - Set
IS_TESTING=falsein.envor docker-compose.yml - "Email not confirmed" - Check your email for confirmation link, or disable email confirmation in Supabase dashboard
- "Invalid token or user not found" - Check that your token is valid and not expired
- Connection errors - Verify SUPABASE_URL and SUPABASE_KEY are correct