Using multipage functionality and user roles

I have created a Streamlit app using the multipage functionality. So far, great experience.

Now I wondered if there is any possibility to include user roles? Is it possible to only show those pages in the navigation to which the respective user may have access? And can I restrict these pages from beeing rendered?

I have no clue how could I adress this point but maybe it is not possible at all?

Thx a lot

Hey @dirk! Welcome on our forum :slight_smile:

Happy that you like multipage apps!

  • About user roles: you may want to have a look at st.experimental_user, it’s a Streamlit native way (although experimental) for you to get information on the user. This is working when your app is deployed on Streamlit Cloud, and would give you user data whenever they’re signed in on Cloud, too. See the docs
  • About pages being hidden depending on x/y/z: currently this is not natively supported with our multipage apps. Any page in pages/*.py will be displayed in the sidebar. Now, playing with st.experimental_user, you could still show an empty page for those that don’t have access (although it’s clickable from the sidebar):
# pages/

AUTHORIZED_EMAILS = st.secrets.emails 

import streamlit as st 

if "email" in st.experimental_user:
    st.error("You are not authorized to view this page, sorry!")

Hey @arnaud,

Thank you for your explanations.

In fact, I deploy the application via docker. So I guess I have to take a different approch for this.

That’s right, my example above would only work on Streamlit Community Cloud!

If you’re not on Community Cloud, one option would be to use Auth0 to get a verified email of the user, and then check that against approved users. New Component: auth0_component, a simple way to authenticate a user