How to hide all pages before login

One way to do this is use GitHub - blackary/st_pages: An experimental version of Streamlit Multi-Page Apps. There is a hide_pages() function which you can see at work https://github.com/blackary/st_pages/blob/main/example_app/example_four.py

You can see the full app in action here https://st-pages.streamlit.app/

Thanks this helped a lot. It worked.

Thanks for the help. But I still cannot figure it out. Can you provide code for any sample multipage app with the login feature, if possible? @blackary @rafikul-m @NELSON_JOSEPH

Here’s one way to accomplish that @Anandhu_H

import streamlit as st
from st_pages import show_pages, Page, hide_pages

show_pages(
    [
        Page("streamlit_app.py", "Home", icon="🏠"),
        Page("secret_page.py", "After Login", icon="🔒"),
    ]
)

if "logged_in" not in st.session_state:
    st.session_state.logged_in = False


def log_in():
    username = st.session_state.username
    if username == "test":
        st.session_state.logged_in = True
    else:
        st.write("Invalid username")


def log_out():
    st.session_state.logged_in = False


if not st.session_state.logged_in:
    hide_pages(["After Login"])
    st.text_input("Username (use 'test')", key="username", on_change=log_in)
else:
    st.button("Log out", on_click=log_out)
1 Like

You can check this repository. It’s a fully working application with a login landing page and multiple pages within it that can be accessed from the left slide bar. GitHub Repository

1 Like