Skip to content

actindev/supaauth

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Streamlit SupaAuth Component

SupaAuth - From Zero to Auth in Under 1 Minute

A Streamlit component for Supabase authentication


A modern, easy-to-use Streamlit component for Supabase authentication.


Streamlit Supabase Python React PyPI version


✨ Features

  • πŸ” Complete authentication system with email/password
  • πŸš€ Easy integration with Streamlit apps
  • 🎨 Modern UI with dark/light theme support
  • πŸ“± Fully responsive design
  • πŸ”’ Secure authentication flow
  • 🌐 Password reset functionality
  • πŸ’ͺ Real-time authentication state updates
  • ⚑ Powered by Supabase

πŸš€ Quick Start

Prerequisites

  • Python 3.7 or higher
  • Streamlit
  • A Supabase project

Installation

  1. Install the component:

    pip install streamlit-supaauth
  2. Use in your Streamlit app:

    import streamlit as st
    from streamlit_supaauth import supaauth_component
    
    # Basic usage
    result = supaauth_component(
        supabase_url="your-supabase-url",
        supabase_anon_key="your-anon-key",
        mode="signin",  # or "signup", "reset-password"
        theme="dark",   # or "light"
        key="auth"
    )
    
    if result:
        st.write("Authentication result:", result)
  3. Set up your Supabase credentials:

    # In your Streamlit secrets.toml file
    SUPABASE_URL = "your-supabase-url"
    SUPABASE_ANON_KEY = "your-anon-key"
  4. Run your Streamlit app:

    streamlit run your_app.py

πŸ“– Component Parameters

Parameter Type Default Description
supabase_url str None Your Supabase project URL
supabase_anon_key str None Your Supabase anonymous key
mode str "signin" Authentication mode: "signin", "signup", or "reset-password"
redirect_to str "/dashboard" URL to redirect after successful authentication
theme str "dark" Component theme: "dark" or "light"
key str None Unique key for the component instance

πŸ”„ Return Values

The component returns a dictionary with authentication results:

{
    "event": "SIGNED_IN",  # Event type
    "user": {...},         # User object from Supabase
    "session": {...},      # Session object from Supabase
    "timestamp": "..."     # ISO timestamp of the event
}

Event Types

  • SIGNED_IN - User successfully signed in
  • SIGNED_UP - User successfully signed up
  • SIGNED_OUT - User signed out
  • PASSWORD_RECOVERY - Password reset email sent

🎨 Themes

The component supports two themes:

  • Dark Theme (theme="dark") - Dark background with light text
  • Light Theme (theme="light") - Light background with dark text

πŸ”§ Development

To set up the development environment:

  1. Clone the repository:

    git clone https://github.com/Gitmaxd/supaauth.git
    cd supaauth
  2. Install Python dependencies:

    pip install -e .
  3. Install frontend dependencies:

    cd streamlit_supaauth/frontend
    npm install
  4. Start the frontend development server:

    npm start
  5. Run the example Streamlit app:

    streamlit run example_app.py

πŸ“¦ Building for Production

  1. Build the frontend:

    cd streamlit_supaauth/frontend
    npm run build
  2. Update the _RELEASE flag in __init__.py:

    _RELEASE = True
  3. Build and upload to PyPI:

    python setup.py sdist bdist_wheel
    twine upload dist/*

πŸ” Environment Variables

For security, store your Supabase credentials in Streamlit secrets:

.streamlit/secrets.toml

SUPABASE_URL = "https://your-project.supabase.co"
SUPABASE_ANON_KEY = "your-anon-key"

Then access them in your app:

supabase_url = st.secrets["SUPABASE_URL"]
supabase_anon_key = st.secrets["SUPABASE_ANON_KEY"]

πŸ“‹ Example Usage

Here's a complete example of using the component in a Streamlit app:

import streamlit as st
from streamlit_supaauth import supaauth_component

st.set_page_config(page_title="My App", page_icon="πŸ”")

st.title("πŸ” My Secure App")

# Authentication component
auth_result = supaauth_component(
    supabase_url=st.secrets["SUPABASE_URL"],
    supabase_anon_key=st.secrets["SUPABASE_ANON_KEY"],
    mode="signin",
    theme="dark",
    key="main_auth"
)

# Handle authentication result
if auth_result:
    if auth_result["event"] == "SIGNED_IN":
        st.success(f"Welcome, {auth_result['user']['email']}!")
        
        # Your authenticated app content here
        st.write("πŸŽ‰ You are now logged in!")
        st.write("User data:", auth_result["user"])
        
    elif auth_result["event"] == "SIGNED_UP":
        st.info("Please check your email to verify your account.")
        
    elif auth_result["event"] == "PASSWORD_RECOVERY":
        st.info("Password reset email sent!")
else:
    st.info("Please sign in to continue.")

πŸ› οΈ Customization

The component is built with React and can be customized by modifying the source code:

  • Styling: Edit streamlit_supaauth/frontend/src/styles.css
  • Components: Modify files in streamlit_supaauth/frontend/src/components/
  • Main Logic: Update streamlit_supaauth/frontend/src/SupaAuthComponent.tsx

πŸ” Troubleshooting

Common Issues

  1. Component not loading: Make sure you have the correct Supabase URL and anon key
  2. Styling issues: Check that the CSS is properly loaded
  3. Authentication errors: Verify your Supabase project settings and RLS policies

Debug Mode

Set _RELEASE = False in __init__.py to enable development mode with hot reloading.

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Streamlit for the amazing framework
  • Supabase for the backend-as-a-service platform
  • React for the component framework

πŸ“ž Support


Made with ❀️ by @GitMaxd
  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ’¬ Support

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❀️ by @GitMaxd

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 86.6%
  • CSS 6.4%
  • Python 4.5%
  • JavaScript 2.2%
  • HTML 0.3%