Hi @Michael13, welcome to the forum!
There’s a subtle piece of that tutorial which is that if you have signed in with a role, then the default page in the list is set to something different. For example:
respond_1 = st.Page(
"respond/respond_1.py",
title="Respond 1",
icon=":material/healing:",
default=(role == "Responder"),
)
See the default=(role=="Responder")
, which means that if your role is Responder, that will be your default page.
If you log in with any role, then the default page will be set appropriately. If you don’t have a role, then the default page will be the first page in the dictionary, which is log out, so that will run automatically.
So, if you want to avoid automatic logout, you can set a different page to be the default one, or (as you’ve noticed), put the logout page to not be the first page in the list.
Here’s a simplified version of that app, and you can see that because I made “settings” to be the default page, you don’t get logged out by default:
import streamlit as st
if "login_status" not in st.session_state:
st.session_state.login_status = False
def login():
if st.button("Login"):
st.session_state.login_status = True
st.rerun()
def logout():
st.session_state.login_status = False
st.rerun()
logout_page = st.Page(logout, title="Log out", icon=":material/logout:")
settings = st.Page(
"settings.py", title="Settings", icon=":material/settings:", default=True
)
account_pages = [logout_page, settings]
if st.session_state.login_status:
pg = st.navigation({"Account": account_pages})
else:
pg = st.navigation([st.Page(login)])
pg.run()