I have a local app with multipages and am trying to add authentication to it. If I am logged in, these are the pages I used using st_pages
...
if user:
st.success("Logged In Sucessfully {}".format(email))
st.session_state.authentication_status = True
show_pages(
[
Page("pages/generate.py", "generate", icon="đź“ť"),
...
Page("pages/logout.py", "logout", icon="🚪"),
Page("app.py", ""),
]
)
Notice my main page app.py
must be added or else switch_page("")
doesn’t work.
I made a logout page since this is the only way I found to create a “button” on the sidebar along with other pages (as opposed to st.sidebar
which did not work for me). The logout page looks like this
import streamlit as st
from streamlit_extras.switch_page_button import (
switch_page,
) # import the switch_page function
from components.authenticate import supabase_client
from time import sleep
from st_pages import hide_pages
# Logout page
def logout():
if not st.session_state.authentication_status:
st.info("Please Login from the Home page and try again.")
st.stop()
st.session_state.authentication_status = False # set the logged_in state to False
res = supabase_client.auth.sign_out()
if res:
st.error(f"Error logging out: {res}")
else:
st.success("Logged out successfully")
sleep(5)
switch_page("") # switch back to the login page
def main():
if st.session_state.authentication_status:
st.title("Logout")
logout()
if __name__ == "__main__":
main()
Here switch_page
should direct user to the main page route (/
) after logging out - it does, but the route gets stuck at /logout
. When logging back in, the error pops up
Page not found The page that you have requested does not seem to exist. Running the app's main page.
Ideally I just want to return to main page app.py
without having to show_page([..., Page("app.py", "")])
and subsequently having to use switch_page("")
which only works if app.py
exists in the page lists.
Without a minimal example of this, does anyone have any experience / advise on this?