Hi,
I have a simple Streamlit app where the user logs in and some calculations are done (after log in). I would like to enforce logout after 1 hour of inactivity of the user.
This topic has been discussed here, here or here but it seems to me that there is no clear solution.
Here is my code. Basically, there is the authentication part. And if the user is logged-in, some stuff are displayed. I enforce logout 1 hour once this stuff is displayed through a time.sleep(). It works well.
BUT it causes a strange behaviour where old content is displayed multiple times (fading out content). How could I change to keep a logout after 1 hour but without this fading out thing?
import streamlit as st
import time
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader
inactivity_timeout=10
#AUTHENTICATION
with open('config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days']
)
authenticator.login()
if st.session_state["authentication_status"] is False:
st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] is None:
st.warning('Please enter your username and password')
elif st.session_state["authentication_status"]:
authenticator.logout()
st.write ('Some stuff')
# Logout if time elapsed
time.sleep(inactivity_timeout)
authenticator.authentication_handler.execute_logout()
authenticator.cookie_handler.delete_cookie()