diff --git a/credentials.yml b/credentials.yml index acd1eae..e4c3569 100644 --- a/credentials.yml +++ b/credentials.yml @@ -6,7 +6,7 @@ credentials: logged_in: False password: abc cookie: - expiry_days: 30 + expiry_days: 0 key: some_signature_key # Must be string name: some_cookie_name pre-authorized: diff --git a/frontend/st_utils.py b/frontend/st_utils.py index e69df40..7a23fdb 100644 --- a/frontend/st_utils.py +++ b/frontend/st_utils.py @@ -95,7 +95,8 @@ 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'], @@ -103,16 +104,13 @@ def auth_system(): 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())