open-notebook/pages/stream_app/auth.py
Luis Novo d7b0fff954
Api podcast migration (#93)
Creates the API layer for Open Notebook
Creates a services API gateway for the Streamlit front-end
Migrates the SurrealDB SDK to the official one
Change all database calls to async
New podcast framework supporting multiple speaker configurations
Implement the surreal-commands library for async processing
Improve docker image and docker-compose configurations
2025-07-17 08:36:11 -03:00

52 lines
No EOL
1.6 KiB
Python

import os
import streamlit as st
def check_password():
"""
Check if the user has entered the correct password.
Returns True if authenticated or no password is set.
"""
# Get the password from environment variable
app_password = os.environ.get("OPEN_NOTEBOOK_PASSWORD")
# If no password is set, skip authentication
if not app_password:
return True
# Check if already authenticated in this session
if "authenticated" in st.session_state and st.session_state.authenticated:
return True
# Show login form
with st.container():
st.markdown("### 🔒 Authentication Required")
st.markdown("This Open Notebook instance is password protected.")
with st.form("login_form"):
password = st.text_input(
"Password",
type="password",
placeholder="Enter password"
)
submitted = st.form_submit_button("Login")
if submitted:
if password == app_password:
st.session_state.authenticated = True
st.success("Successfully authenticated!")
st.rerun()
else:
st.error("Incorrect password. Please try again.")
# Stop execution if not authenticated
if "authenticated" not in st.session_state or not st.session_state.authenticated:
st.stop()
return True
def logout():
"""Clear authentication from session state."""
if "authenticated" in st.session_state:
del st.session_state.authenticated