Skip to content

Commit

Permalink
Merge pull request #167 from hummingbot/feat/improve_auth
Browse files Browse the repository at this point in the history
Feat/improve auth
  • Loading branch information
cardosofede authored Jul 23, 2024
2 parents 7f0df00 + ef24915 commit 907132e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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 907132e

Please sign in to comment.