Right way to manage same user opening multiple sessions

Updated version by @IndigoJay:

Replacing the deprecated @st.experimental_singleton with @st.cache_resource() st.cache_resource - Streamlit Docs

import streamlit as st
import datetime as dt

# Example list of users
USER_LIST = ['Barbara','Christopher']

# Updates the active session for a given user
#def get_active_session(username):
#    return st.session_state.session_id

def get_active_session(username):
    return st.session_state.session_id

# App when logged out
if 'session_id' not in st.session_state:
    st.warning('You are currently logged out')

    #Login form
    with st.form('Login form'):
        username = st.text_input('Username (try "Barbara" or "Christopher")')
        sign_in = st.form_submit_button('Sign In')
    if sign_in and username in USER_LIST:
        st.session_state.user_id = username
        st.session_state.session_id = username + '_' + str(dt.datetime.now())
        aux_active_session = get_active_session(st.session_state.user_id)

# App when logged in and session active
elif st.session_state.session_id == get_active_session(st.session_state.user_id):
    st.success('You are currently logged in')
    st.write('Session ID: ',st.session_state.session_id)
    st.button('Useless button')

    # Logout button
    if st.button('Logout'):
        for key in st.session_state.keys():
            del st.session_state[key]

# App when session expired
    st.info('Your session has expired')
    for key in st.session_state.keys():
        del st.session_state[key]
    st.button('Return to homepage')