File size: 914 Bytes
5fb2d40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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

# Ensure the DB tables exist before we fetch users
init_db()

# Instantiate your user repository
user_repo = UserRepo(settings.database_url)

def init_auth():
    users = user_repo.get_all_users()
    creds = {
        u.username: {"name": u.full_name, "password": u.hashed_password}
        for u in users
    }
    return Authenticate(
        credentials=creds,
        cookie_name="quantum_healthcare_auth",
        key=settings.secret_key,
        cookie_expiry_days=1,
    )

# Create the authenticator at import time
authenticator = init_auth()

def require_login():
    name, authentication_status, username = authenticator.login("Login", "sidebar")
    if not authentication_status:
        st.stop()
    return username