MedQA / services /auth.py
mgbam's picture
Update services/auth.py
86a454c verified
raw
history blame
861 Bytes
import streamlit as st
from streamlit_authenticator import Authenticate
from config.settings import settings
from repositories.user_repo import UserRepo
from models.db import init_db
# Create tables if they don't exist
init_db()
user_repo = UserRepo(settings.database_url)
def init_auth():
users = user_repo.get_all_users()
user_map = {
u.username: {"name": u.full_name, "password": u.hashed_password}
for u in users
}
creds = {"usernames": user_map}
return Authenticate(
credentials=creds,
cookie_name="quantum_healthcare_auth",
key=settings.secret_key,
cookie_expiry_days=1,
)
authenticator = init_auth()
def require_login():
name, authentication_status, username = authenticator.login("Login", "sidebar")
if not authentication_status:
st.stop()
return username