File size: 1,252 Bytes
38c235b
1942e54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
import streamlit as st
import streamlit_authenticator as stauth

# Define user authentication
users = {
    "credentials": {
        "usernames": {
            "user1": {"name": "User One", "password": "password1"},
            "user2": {"name": "User Two", "password": "password2"},
        }
    },
    "cookie": {
        "expiry_days": 30,
        "key": "my_secret_key",
        "name": "streamlit_auth",
    },
}

# Initialize the authenticator
authenticator = stauth.Authenticate(
    credentials=users["credentials"],
    cookie_name=users["cookie"]["name"],
    key=users["cookie"]["key"],
    cookie_expiry_days=users["cookie"]["expiry_days"],
)

# Login/Logout flow
name, authentication_status, username = authenticator.login("Login", "main")

if authentication_status:
    st.success(f"Welcome, {name}!")
    user_input = st.text_input("Type a message here:")
    if user_input:
        st.write(f"Response: hi")
    authenticator.logout("Logout", "sidebar")
elif authentication_status == False:
    st.error("Username/password is incorrect.")
elif authentication_status == None:
    st.warning("Please enter your username and password.")

# Note: You can replace `stauth` with your custom Google OAuth implementation for more complex use.