How to manage a multipage app with user authentication

Is it possible to use multipage app feature with user authentication with streamlit? I’ve made a multipage app with strealit-authenticator, but when i make an authentication for user in my “main page” the login page appear and protect only on the “main page”, other pages can access on the sidebar without having to login.
Please help! Thank you…


i also encountered this question. have you already solved it?

This can be soived using st.session_state in Streamlit. You can setup the main file like:

import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader

st.set_page_config(page_title="Home", page_icon="🏠", layout="wide")

def st_authenticator():
    with open('data/config.yaml') as file:
        config = yaml.load(file, Loader=SafeLoader)

    authenticator = stauth.Authenticate(

    return authenticator

authenticator  = st_authenticator()
name, authentication_status, username = authenticator.login("Login", "main")

if authentication_status:
    st.session_state.authentication_status = True
    authenticator.logout('**Logout**', 'main', key='unique_key')
elif authentication_status is False:
    st.session_state.authentication_status = False
    st.error('Username/password is incorrect')
elif authentication_status is None:
    st.session_state.authentication_status = None
    st.warning('Please enter your username and password')

And include the below line of code in other pages (after importing libraries). For example in ‘pages/

# import libraries here

if not st.session_state.authentication_status:'Please Login from the Home page and try again.')

# rest of the operations

Hi, I’m using this solution. But i found an issue if you reload the page in another page that doesn’t have the st.session_statue.authentication_status initialization it shows an error because it doesn’t exist.

Also is there any way to hide the options in the multi page menu in the case it isn’t initialized? or to redirect to the home and go back?

Thanks in advance