This project demonstrates how to implement Supabase authentication in a Reflex web application. It includes both email/password and Google OAuth authentication methods.
- Python 3.8 or higher
- Basic understanding of Python
- A Supabase account (free tier works fine)
- Go to Supabase and sign up/login
- Create a new project
- Once created, go to Project Settings -> API to find your project credentials
- Copy the example environment file:
cp .env.example .env
- In your
.env
file, fill in the following values from your Supabase project:
SUPABASE_IDENTIFIER
: Your project identifier (e.g., from "https://x123456789x.supabase.co" take "x123456789x")SUPABASE_PASSWORD
: Your project's database passwordSUPABASE_KEY
: Your project's anon/public key
- Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
- Install dependencies:
# Option 1: Using pip
pip install -r requirements.txt
# Option 2: Using uv (faster)
uv pip install -r requirements.txt
# Optional: Recompile requirements
uv pip compile requirements.in -o requirements.txt
- Start the Reflex development server:
reflex run
- Open your browser and navigate to http://localhost:3000
-
Email/Password Authentication:
- Click "Sign Up" to create a new account
- Use your email and a password
- Verify confirmation email
- You should be able to log in successfully
- You should be automatically logged in and see the protected main page
- should also be logged in automatically on other tabs but not when re-opening the browser for whatever reason
-
Google Authentication:
- Click the Google sign-in button
- Note: Currently experiencing some cookie-related issues with Google auth and email/password auth
- Has some cookie-handling issues that are being investigated
- Email/password authentication is working better than Google auth
The Discord of both Supabase and Reflex are very active and the mods are very helpful.
The main application code is located in the supabase_auth_X_reflex/
directory. Here's how the code is organized:
supabase_auth_X_reflex.py
: The main entry point of the application. It determines which component to show based on the authentication state.auth_state.py
: Manages the authentication state using Reflex's State class.auth_component.py
: The login/signup UI component shown to unauthenticated users.main_app_component.py
: The protected content shown to authenticated users (currently contains dummy content).
The app follows a simple authentication flow:
- When a user visits the site, the app checks for a user_id in the AuthState
- If no user_id is found (user not authenticated):
- The
auth_component
is displayed - User can choose to login with email/password or Google
- The
- If user_id exists (user is authenticated):
- The
mainApp
component is displayed - Currently shows placeholder content for demonstration
- The