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
Dirk

1 Like

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/sensitive_page.py

AUTHORIZED_EMAILS = st.secrets.emails 

import streamlit as st 

if "email" in st.experimental_user:
    if st.experimental_user.email in AUTHORIZED_EMAILS:
        display_app()
else:
    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

2 Likes

Hi! I was wondering if it is still not possible to hide a page to certain users. I am hiding the content of the page, but I would preferr to hide the page from the sidebar.

Thanks

You can hide the page via css using the hide_pages function in st_pages GitHub - blackary/st_pages: An experimental version of Streamlit Multi-Page Apps