Returning to main page for multipage app

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?

Hey @hud! :wave:

We’re not supporting Python 3.12 yet. We’ll work on it soon but are currently blocked by pyarrow not supporting 3.12 yet. According to this issue, they will work on it in the next few weeks though.

I hope this helps.

Best,
Charly

looking forward for the support. Can’t wait to build a streamlit app with python3.12 …

This is a bit confusing. The OP doesn’t seem to be specifically related to python 3.12.

pyarrow 14 was released more than two weeks ago and I have been using streamlit with python 3.12 without issues. There is not explicit support for it, though. But it works as far as I can tell

Sorry for the delay. Yes this error has nothing to do with 3.12 I am using 3.9. The question really was about returning to main app page using st_pages. Any ideas how to do this?

1 Like