I have the following bug, every time I login in I am able to click trough the different pages using this on the main page:
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â],
config[âpreauthorizedâ]
)
name, authentication_status, username = authenticator.login(location=âmainâ)
st.write(name, authentication_status, username)
st.session_state[âauthentication_statusâ] = authentication_status
if st.session_state[âauthentication_statusâ]:
print(âHello worldâ)
and then on every page only the part:
if st.session_state[âauthentication_statusâ]:
print(âHello worldâ)
The problem is when I reload the page completely by clicking on the browsers reload arrows, I get the following error:
KeyError: âst.session_state has no key âauthentication_statusâ. Did you forget to initialize it? More info: Add statefulness to apps - Streamlit Docsâ
I go to reduce the amount of times this message was delivered by adding the full login module again on every page:
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â],
config[âpreauthorizedâ]
)
name, authentication_status, username = authenticator.login(location=âmainâ)
st.write(name, authentication_status, username)
st.session_state[âauthentication_statusâ] = authentication_status
if st.session_state[âauthentication_statusâ]:
print(âHello worldâ)
Never the less, every now and then I still get the error:
KeyError: âst.session_state has no key âauthentication_statusâ. Did you forget to initialize it? More info: Add statefulness to apps - Streamlit Docsâ
Any work arounds? to my feeling streamlit, when sometimes reloading a page completely, struggles to get the correct authentication status? any opinions?