gravity / menu.py
ayushnoori's picture
Add user auth
01b734e
raw
history blame
1.32 kB
# From https://docs.streamlit.io/develop/tutorials/multipage/st.page_link-nav
import streamlit as st
def authenticated_menu():
# Show a navigation menu for authenticated users
# st.sidebar.page_link("app.py", label="Switch Accounts", icon="πŸ”’")
st.sidebar.page_link("pages/user.py", label="Profile", icon="πŸ‘€")
st.sidebar.page_link("pages/input.py", label="Input", icon="πŸ’‘")
st.sidebar.page_link("pages/validate.py", label="Validate", icon="βœ…")
st.sidebar.page_link("pages/explore.py", label="Explore", icon="πŸ”")
if st.session_state.role in ["admin"]:
st.sidebar.page_link("pages/admin.py", label="Manage Users", icon="πŸ”§")
def unauthenticated_menu():
# Show a navigation menu for unauthenticated users
st.sidebar.page_link("app.py", label="Log In", icon="πŸ”’")
def menu():
# Determine if a user is logged in or not, then show the correct navigation menu
if "role" not in st.session_state or st.session_state.role is None:
unauthenticated_menu()
return
authenticated_menu()
def menu_with_redirect():
# Redirect users to the main page if not logged in, otherwise continue to
# render the navigation menu
if "role" not in st.session_state or st.session_state.role is None:
st.switch_page("app.py")
menu()