Hello fellas ! Is there a way to kill all sessions of a user ?
this is my function, executed is seperate threat, it makes regular checks on config.yaml, if condition is met i want o kill all user sessions. this is my function
def terminate_user():
while True: # No exit condition, so the loop will run indefinitely
with open(‘config.yaml’, ‘r’) as file:
config = yaml.safe_load(file)
# Remove terminated users from the config file
for username, user_info in list(config['credentials']['usernames'].items()):
expiration_datetime = user_info.get('expiration_datetime')
current_time = datetime.now()
if expiration_datetime is not None and current_time >= expiration_datetime:
authenticator.logout('main')
del config['credentials']['usernames'][username]
print(f"User {username} has been deleted.")
st.session_state['user_terminated'] = True
print("session state user terminated is True")
st.session_state.clear()
# Save the updated config file
with open('config.yaml', 'w') as file:
yaml.safe_dump(config, file)
file.flush()
os.fsync(file.fileno())
session_timeout(1)
time.sleep(10)
Function to start the session checker in a background thread
def start_session_checker():
checker_thread = threading.Thread(target=terminate_user, daemon=True)
checker_thread.start()
Call the start_session_checker function to initiate the background thread
start_session_checker()
and this is config.yaml (im using authentication) : cookie:
expiry_days: 30
key: some_signature_key
name: some_cookie_name
credentials:
usernames:
dalia@gmail.com:
email: rbriggs@gmail.com
expiration: 60
expiration_datetime: null
failed_login_attempts: 0
firstlogin: null
logged_in: false
name: c
password: abc
dalia@gmail.com:
email: rbriggs@gmail.com
expiration: 60
expiration_datetime: null
failed_login_attempts: 0
firstlogin: null
logged_in: false
name: c
password: abc
pre-authorized:
emails:
*knowing that using pyautogui cntrl + w only close the vscode editor not the session
*if i use switch_page i got streamlit.errors.NoSessionContext
nb: im new using streamlit