Skip to content

Commit

Permalink
(feat) improve auth initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cardosofede committed Jul 23, 2024
1 parent c750f11 commit ef24915
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions frontend/st_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,22 @@ def auth_system():
else:
with open('credentials.yml') as file:
config = yaml.load(file, Loader=SafeLoader)
if "authenticator" not in st.session_state:
if "authenticator" not in st.session_state or "authentication_status" not in st.session_state or not st.session_state.get(
"authentication_status", False):
st.session_state.authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['pre-authorized']
)
st.session_state.authenticator.login()
if st.session_state["authentication_status"]:
st.session_state.authenticator.logout(location="sidebar")
st.sidebar.write(f'Welcome *{st.session_state["name"]}*')
show_pages(main_page() + private_pages() + public_pages())

else:
show_pages(main_page() + public_pages())
st.session_state.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')
else:
st.session_state.authenticator.logout(location="sidebar")
st.sidebar.write(f'Welcome *{st.session_state["name"]}*')
show_pages(main_page() + private_pages() + public_pages())

0 comments on commit ef24915

Please sign in to comment.